Search code examples
cocoaiboutlet

Creating outlets from interface builder to a NSObject class not working


I am new to using interface builder. Generally I create stuff programmatically but for this project in particular I have to use it, because I am working with a guy that just knows how to work with IB.

Said, that, I have to create a NSObject class and I want to create outlets from objects on interface builder to that class. Dragging the New Referencing Outlet (+) from interface builder to the class header is not doing the trick.

How do I do that?


Solution

  • In your class *.h add an outlet to the inferface, e.g.

    IBOutlet NSButton *connectToThisButton; //choose the name you like

    In IB CONTROL-drag from your button to the class, where your IBOutlet is defined. Leave the mousebutton and select connectToThisButton. Maybe you have to save it in XCode, before you can do this in IB.

    Define a method for action after the end of the interface-section:

    • ( IBAction) doSomeActionWithButton:(id)sender; //choose the name you like In IB CONTROL-drag from your class to the button, where your IBOutlet is defined.