Look at Apple's Cocoa tutorial documentation that comes with Xcode 4, this is rather fundamental to the Xcode/Cocoa/interface designer model!
In outline:
@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 designer) you need to:
- Add an instance of
MyCustomClass
- select Object from the Object Library and drag it onto your Objects (usually on lhs of canvas) or the design canvas (it will just go to Objects and 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 up an instance of MyCustomClass
will be created.
- Select your
NSButton
on the design canvas, select the Connections tab in the Inspector. Click and drag from selector under Sent Actions to your MyCustomClass
under Objects. On releasing you'll get a menu of IBAction
s to select from, pick myButtonClickAction
.
- You'll probably want to add an
IBOutlet
to your application delegate to link to the custom object instance that has been created, if you don't you won't have a direct way of accessing it. The process to do this follows the same pattern as for the IBAction
above.
That is it, in words (pictures help), and very briefly.
Now go read those tutorials!