Tutorial :when to use a IBOutlet?



Question:

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?


Solution:1

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.


Solution:2

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)


Solution:3

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;


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »