fabian789
fabian789

Reputation: 8412

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.

Upvotes: 9

Views: 14782

Answers (2)

meda
meda

Reputation: 45500

@Bavarious asnwer is good, folks like me always need a good snippet of code:

appDelegate = (AppDelegate*)[[NSApplication sharedApplication] delegate];
self.masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
[appDelegate.window.contentView replaceSubview:self.view with:self.masterViewController.view];

I create the appDelegate object because it is being called from an NSViewController otherwise you can get the view from self.

Upvotes: 0

user557219
user557219

Reputation:

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.

Upvotes: 13

Related Questions