Search code examples
objective-ccocoanswindownswindowcontrollernsviewcontroller

NSWindowController and NSViewController


Probably a pretty simple question, but I can't get my head around it.

I would like to create some sort of wizard: An NSWindow appears as a sheet from another NSWindow and should show three different NSViews one after another.

I think I should create a custom NSWindowController and three NSViewControllers but I don't know how to how to set up the controllers and how to exchange the views.


Solution

  • In a nutshell, your window controller would instantiate the three view controllers, have a host view, and add -[NSView addSubview:] or remove -[NSView removeFromSuperView] the view controllers’ views as subviews of the host view. Depending on how you structure your code, you can also use -[NSView replaceSubview:with:] to replace a subview with another one.

    Apple’s View Controller sample code features view switching using view controllers.