-
What is the purpose of using IBOutlet & IBAction?
over 9 years ago
-
over 9 years ago
Hi Devendra,
IBOutlet refers to UI objects where as IBAction refers to UI Object actions. IBAction and IBOutlet are macros referred to the Interface Builder.
IBAction resolves to void and IBOutlet resolves to nothing, but they can be used in Interface builder to link UI elements to your code.
-
over 9 years ago
Hi Devendra,
IBOutlet and IBActions don't do anything programatically. There are "hookups" defined to connect "views" and "actions" from Interface Builder.
We add a keyword IBOutlet while declaring a property. It is same as we declare other properties, but in this case, we can "hook" this outlet from Interface Builder.
Examples as below:
IBOutlet
If we place a UILabel on a UIView in storyboard/XIB and we need to change its value through code. We need to "hook" it to code. To do that, we need to specify IBOutlet keyword while declaring a property.
IBAction
Similarly, Lets say we have a UIButton in storyboard/XIB, and we need to trigger an action on it. We need to connect it with a function in code. This function should have the return type as "IBAction". The interface then gets to know that it can connect with this function. If we pass "void" as return type, then it will not display in Interface Builder.
What happens during runtime
During runtime, the "IBOutlet" is deleted and "IBAction" is replaced with "void".
-
2 Answer(s)