NSWindowController and NSViewController

fabian789 picture fabian789 · Feb 20, 2011 · Viewed 14k times · Source

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.

Answer

user557219 picture user557219 · Feb 20, 2011

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.