Look at the Apple Cocoa design documentation that comes with Xcode 4, which is pretty fundamental to the Xcode / Cocoa / interface designer model.
In the scheme:
@interface MyCustomClass - (IBAction) myButtonClickAction:(id)sender; @end @implementation MyCustomClass - (IBAction) myButtonClickAction:(id)sender { NSLog(@"My button has been clicked"); } @end
Now in the interface designer (just open the .xib file in Xcode to get the constructor) you need:
- Add an instance of
MyCustomClass - select an object from the library of objects and drag it onto your objects (usually on lhs of canvas) or onto the design canvas (it just goes to the objects and does not create a graphic widget on the canvas). Now select the added object and in the inspector (usually on rhs of canvas) set the class to MyCustomClass . Now, when your application starts, an instance of MyCustomClass will be created. - Select
NSButton on the design canvas, select the Connections tab in the Inspector. Click and drag from the selector in the Sent Actions section to MyCustomClass in the Objects section. When released, you will get an IBAction menu to select, select myButtonClickAction . - You will probably want to add an
IBOutlet to the delegate of your application to associate it with the instantiated custom object created, if you do not, you do not have direct access to it. The process for this follows the same pattern as for the IBAction above.
That is, in words (image help) and very briefly.
Now read these lessons!
source share