Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • What is the purpose of using IBOutlet & IBAction?

    • 2
    • 2
    • 0
    • 2
    • 0
    • 0
    • 0
    • 670
    Answer it

    As you all know that at compile time
    1. All IBOutlet keywords are removed entirely.
    2. All IBAction keywords are replaced by void because actions invoked by user interface controls are not expected to have a return value.

    The question then arises, "What is the purpose of using IBOutlet & IBAction method"

 2 Answer(s)

  • 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.

  • 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".

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: