Normally you would create at least one controller object (the "application controller", just an NSObject subclass) where you could write methods that get called by menu items. Then in Interface Builder, you instantiate the controller and control-drag from the menu item to your controller object and select the target method. You could also have more controller objects that manage specific parts of your application.
I think if you download some of the simple Cocoa applications and examine how they are constructed (including looking at all the connections and objects in IB), it will help you. That said, the process is not exactly the same for every developer or every application. There is often more than one way to go about it.
Or, create a new cocoa Application project and go to your mainMenu nib. Click on First responder, go to Classes view and an action (You can only add actions to first responder) e.g. testButton.
Don't connect anything to something (control-drag)
Then go to your MyDocument.h in xcode and add:
Code:
(IBAction) testButton:(id)sender {
NSLog(@"click");
}
And it works, it's magic. I once asked this same question and got a response from a cocoa guru explaining how it works. If you want to know how it works, you could try looking for that thread.
What method you should use, depends - I think - on how your program is designed. My explanation is the only way to do it for separate Menu nib's, I think. While the method from the other guy works well when the actions and the code are together in one logic unit described by a nib. That is, you can't control-drag across nib's.