I'm coming over from iOS development and I can't figure out this basic thing: if I open MainMenu.xib in Interface Builder and I drag a button onto the main window's view, what class should I connect that button's action to -- the App Delegate?
If I want to add a View Controller, how do I "assign" it to the main window's view in MainMenu.xib?
What is the pattern -- to use an NSViewController, to use an NSWindowController, or to just shove everything into the App Delegate?
Best How To :
So the default is that your main application window is an outlet in the app delegate. You should keep
MainMenu.xib's owner as the app delegate.
A common alternative, if you are creating your own custom window controller, is to create a property in the AppDelegate of type
CustomWindowController, then in the
-applicationDidFinishLaunching, instantiate your custom window and show it:
windowController = [[MyWindowController alloc] initWithWindowNibName:@"MyWindow"];
Of course this means you can sever the connection to the default window they give you.
If you add any buttons, you will want to connect them to the owner of the superview they are in. Whether that be the app delegate if you are working in the
MainMenu.xib default window, or the custom window controller if you have created your own window, or a custom view controller if you are creating your own view.
If you want to add a view controller, you first have to create the new Cocoa class as you would with a CocoaTouch class. Then in the Interface Builder, go to the Object Library at the bottom right and search for "Object". Drag that into your Document Outline, and from there you can set up the connections from your view into your new view controller.
The pattern really depends on what you are doing, but at the end of the day for a basic app you won't need to create your own NSWindowController and you can work with the default
window they give you through the AppDelegate. If you are creating custom views that require some logic, then you will have to create your own custom NSViewControllers and bring them into your xibs