Aug 03

One interesting thing to note about IBOutlet and their connection to Interface Builder. If the field being defined as an IBOutlet does not have an explicit “setting” method, either by manually writing it or by using @property and @synthesize, the route to connect the Nib’s definition to this field in the file is setValue:forKey. This method retains the field that is set as an outlet. Therefore, even though you didn’t retain the field anywhere in your code, you need to release it in your dealloc method.

So, I typically just make sure all outlets are properties.

Tagged with:
Jul 16

Often times you’ll see:

-(IBAction)someMethod:(id)sender

IBAction is the return value of the method, but what is IBAction? IBAction is void. Nothing is returned by the method. It does provide Interface Builder a hint that this should be exposed as a callable action from a UI element.

Tagged with:
Jul 11

When refactoring existing code, be careful to ensure that your Interface Builder outlets are still correct. For example, if I have a simple controller class with the following attributes:

XcodeScreenSnapz004

They are defined as IBOutlet’s and are, therefore, connected in Interface Builder to UI elements.

Interface BuilderScreenSnapz001

Now, let’s say we wish to change the name of “switcher” to “switchElement”. Obviously, the worst thing we could do is make the change manually, even without the Interface Builder connections we’d have to manually update both the .H and the .M files. So, we should make use of Xcode’s refactoring mechanism.

Right click on the attribute in question (“switcher”), and select Refactor

XcodeScreenSnapz005

This will bring up a new Dialog with the “rename” option already selected. Type in the new name, it will identify what files will be changed. You’ll notice that the .H, .M and the nib file are selected for changing.

Once you apply the change, you’ll need to revert the nib in Interface Builder to the version on file. However, Xcode doesn’t handle everything for you, there is one more step that you have to take care of. If you open up the connections part of the UI, you’ll see that it did, in fact, update your connection. But, the old outlet name still appears as another entry and the new name has a warning. The warning is that the class doesn’t have an outlet with the new name.

After banging my head for awhile trying to figure out why they wouldn’t take the final step during a refactor I realized I needed to do one more thing. Save the .M and .H files. Now, everything is in sync and working properly.

Tagged with:
preload preload preload