开发者

when to use a IBOutlet?

I'm a little confused about t开发者_如何学Che IBOutlet.Is it right I should use the IBOutlet when the variable will be changed in the nib?


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.


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)


I am new to IOS. What i understand is you need an identifier (which you assign to your button) for actually manipulating with button event.

Example :

  • You create a button
  • Now if you want to access that button using code you need to assign a name.
  • After assigning a name you can use that name specifier for manipulation.
  • Perform action.

Code:

@property(nonatomic,strong) IBOutlet UIButton *bttn;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜