I was very comfortable with XCode 3 and iOS. I’m now trying to move to XCode 4 and cocoa programming. I’ve been unable to wire up the most simple controls. I start with new empty cocoa application. I drop a button on the form. I control drag the button over the header and drop to get
IBOutlet NSButton *myButton; and
@property (strong) IBOutlet NSButton *myButton;
in init I added:
self.myButton =[[NSButton alloc]init];
since the button is declared strong, I believe it is properly retained.
Later in my code I simply did:
[myButton setTitle:@"this button"];
This code is reached (checked with breakpoint) and myButton is not nil, but the button label on the form does not update. Looking at the connection inspector, myButton does reference “File’s Owner”. I added an IBAction in nearly the same way and it works fine.
Is there something new in XCode 4 needed to properly wire an IBOutlet?
If you are wiring up the control from a NIB into your controller class you don’t have to allocate the button at all – it’s created when the NIB is loaded. What you are doing is replacing the one from the NIB with a new one, hence the inability to update text.