tags:

views:

46

answers:

1

Hi,

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.

+1  A: 

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.

TechZen
FYI: I've never had to do "Reload Class Files". IB picks up changes automatically as long as the .h file is in the project.
Ken Aspeslagh
Really? I still have to use it all the time when I make and save a change to `.h` while the nib is open in IB. I wonder if I missed a new preference setting somewhere.
TechZen
Usually just hitting control-S and saving both the .h and the .xib is enough for me to get fresh .h content into IB.
Dan Ray
Could be. I've been using IB for over ten years now. I might have ingrained habits. Certainly, in the past it was necessary, that's why the choice is there.
TechZen