I have an app where I've got all the views factored out into different NIBs nicely, and the two windows, a document window and the preferences window, are managed by NSWindowController subclasses. Specifically, my document window is in one nib, the toolbar and an empty NSView for the preferences window are in another nib, and each preference pane (5) is in its own nib. The app controller/delegate maintains an array of document window controllers, and one preferences window controller, as well as the managed object context and persistent store for the application (using Core Data for the prefs since it's a database of objects - which the "document" does math on, but doesn't alter or add to the database).
The preferences menu item targets the app controller's showSetupWindow: action:
initWithWindowNibName: is not overridden, although I do have an awakeFromNib:
This windowController has an outlet, a custom view to fill with my preference panes, and an NSViewController.
changeView:, which is giving all the headaches, is as follows:
If anyone can see what's going horribly wrong now, be my guest.
What's happening is that every time changeView: is called, a new document window is created, around addSubview: call. I have no idea why. The other problem is that while the window is resizing properly, most of the prefpane views are out of frame (I can only see the bottom of it), and I can't seem to get them back in. Help!
The preferences menu item targets the app controller's showSetupWindow: action:
Code:
- (IBAction)showSetupWindow:(id)sender
{
if (setupWindowController == nil)
{
setupWindowController = [[CCCESetupWindowController alloc] initWithWindowNibName:@"SetupWindow"];
}
[setupWindowController showWindow:sender];
[setupWindowController changeView:self];
}
Code:
- (void)awakeFromNib
{
for (NSToolbarItem *i in [toolbar items])
{
[i setTarget:self];
[i setAction:@selector(changeView:)];
}
}
changeView:, which is giving all the headaches, is as follows:
Code:
- (IBAction)changeView:(id)sender
{
[self willChangeValueForKey:@"viewController"];
if ([myCurrentViewController view] != nil)
{
[[myCurrentViewController view] removeFromSuperview];
}
if (myCurrentViewController != nil)
{
[myCurrentViewController release];
}
if ([sender respondsToSelector:@selector(tag)])
{
lastTag = [sender tag];
}
else lastTag = kGeneralView;
switch (lastTag) {
case kGeneralView:
myCurrentViewController =[[NSViewController alloc] initWithNibName:@"GeneralSetup" bundle:nil];
break;
case kColorsView:
myCurrentViewController = [[NSViewController alloc] initWithNibName:@"ColorsSetup" bundle:nil];
break;
case kFinishesView:
myCurrentViewController = [[NSViewController alloc] initWithNibName:@"FinishesSetup" bundle:nil];
break;
case kAccessoriesView:
myCurrentViewController = [[NSViewController alloc] initWithNibName:@"AccessoriesSetup" bundle:nil];
break;
case kEmbdedmentsView:
myCurrentViewController = [[NSViewController alloc] initWithNibName:@"EmbedmentsSetup" bundle:nil];
break;
case kInstallationView:
myCurrentViewController = [[NSViewController alloc] initWithNibName:@"InstallationSetup" bundle:nil];
break;
default: break;
}
[myTargetView addSubview:[myCurrentViewController view]];
//[[myTargetView window] setContentView:[myCurrentViewController view]];
[[myTargetView window] setFrame:[[myCurrentViewController view] frame] display:YES animate:YES];
[self didChangeValueForKey:@"viewController"];
}
What's happening is that every time changeView: is called, a new document window is created, around addSubview: call. I have no idea why. The other problem is that while the window is resizing properly, most of the prefpane views are out of frame (I can only see the bottom of it), and I can't seem to get them back in. Help!