What does IB mean in IBAction, IBOutlet, etc..?

后端 未结 3 1230
难免孤独
难免孤独 2021-01-31 08:16

I am very new to iPhone development. I often encounter IBAction, IBOutlet and so on when reading Objective-C and Swift code. What does IB

相关标签:
3条回答
  • 2021-01-31 08:52

    IBAction and IBOutlet are interface Builder Constants IBOutlet:A Controller class can refer to the object in the nib file using a special constant called IBOutlet.

    IBActions:Interface objects in the nib file can be set to trigger specific methods in controller class using IBAction as return type of the method.

    0 讨论(0)
  • 2021-01-31 08:58

    "Interface Builder".

    Before Xcode 4, the interface files (XIBs and NIBs) were edited in a separate program called Interface Builder, hence the prefix.

    IBAction is defined to void, and IBOutlet to nothing. They are just clues to Interface Builder when parsing files to make them available for connections.

    Just to add the reference, inside AppKit/NSNibDeclarations.h you'll find these:

    #ifndef IBOutlet
    #define IBOutlet
    #endif
    
    #ifndef IBAction
    #define IBAction void
    #endif
    

    So, actually, code like this:

    @interface ...
    {
        IBOutlet NSTextField *label;
    }
    - (IBAction)buttonPressed:(id)sender;
    @end
    

    Will be transformed into:

    @interface ...
    {
         NSTextField *label;
    }
    - (void)buttonPressed:(id)sender;
    @end
    

    By the preprocessor, even before the compiler sees it. Those keywords were acting just as clues to Interface Builder.

    0 讨论(0)
  • 2021-01-31 09:12

    IB stands for interface builder, as you connect objects via the interface builder .

    0 讨论(0)
提交回复
热议问题