views:

67

answers:

2

I'm a little confused about the IBOutlet.Is it right I should use the IBOutlet when the variable will be changed in the nib?

+2  A: 

IBOutlet is used when you want to do something with a View you created in Interface Builder. For example, you put a button in Interface Builder and you want to change it's caption/label from your code, attach IBOutlet (with a name such as button1) to that button. Then from your code, you can call [button1 dosomething]. Without having IBOutlet, you have virtually no way to do some action to a View you created in Interface Builder. Short answer is yes, always use IBOutlet whenever you want to do something with a View created in Interface Builder.

VOX
Actually, you can iterate through the subviews or access views by integer tag. Also, the methods in the delegate protocol usually get the relevant object as the first parameter.So it's not like an outlet is the only way to access your UI objects from the view controller.
Seva Alekseyev
A: 

Use IBOutlet when you need to access an object's properties. If you need the text of a UITextField or want to manipulate it in your code, you IBOutlet the text field.

However, if you have, say, a UIButton where you don't need to access its properties, you don't IBOutlet it. You just connect an IBAction to it.

(Not to say that UIButtons shouldn't be IBOutlet'ed, there certainly are cases where it should be, and where UITextFields shouldn't be)

Kurbz