i'm trying to get started with the iPhone development and viewing the Stanford iPhone talks from iTunes U. In the first demo they added Class Actions
and Class Outlets
to an Object开发者_如何转开发. Since they used SDk 3.1 and I have 4.0 things differ a bit. I don't have these elements they have there. I looked but I didn't find anything similar.
How do I do this with SDK 4.0 ?
Thanks
P.S.: Under "Connections" (In the Inspector) I have a button for adding Reference Outlets
, but the hitting the button don't change anything.
You mark an instance variable as an outlet by prefacing its definition with IBOutlet
like so:
IBOutlet UILabel *theLabel;
...
@property (nonatomic, retain) IBOutlet UILabel *theLabel; // can be "assign" instead of "retain"
You mark a method as an action by making its return IBAction
and having the form:
-(IBAction) methodName:(id) sender;
Both IBOutlet and IBAction are used by only Interface Builder to find outlets and actions. Otherwise, they have no effect. You can access the outlet variables just as you would a non-outlet variable and you can call and action method just like any other method.
If you make changes to the class file in Xcode to add outlets and actions while you have the nib open in Interface Builder, you need to use File>Reload All Class Files
in order to force Interface Builder to update itself with the changes. Otherwise, the changes in outlets and actions won't show up in the Interface Builder interface.
精彩评论