PDA

View Full Version : Loading second nib file




Eraserhead
Feb 14, 2007, 06:39 AM
I'm having some problems loading a second nib file containing a window as a sheet. The first method is the init method, the second displays the sheet, it is called from my AppController file.


-(id)initWithMainWindow:(NSWindow *)mainW{
[super init];
mainWindow=mainW;
BOOL success=[NSBundle loadNibNamed:@"MainOffWindows"
owner:self];
if(success!=YES){
NSLog(@"error loading MainOffWindows.nib");
return nil;
}
NSLog(@"nib loading successfully");
return self;
}
-(void)displaySheet{
NSLog(@"sheet class=%@, window class=%@",[sheet class],[mainWindow class]);
[NSApp beginSheet:sheet
modalForWindow:mainWindow
modalDelegate:self
didEndSelector:nil
contextInfo:NULL];
}


After I click on the button to display the sheet I get this from the console (it initialises the second controller first):

2007-02-14 12:32:27.060 MyApp[714] nib loading successfully
2007-02-14 12:32:27.060 MyApp[714] sheet class=(null), window class=NSWindow
2007-02-14 12:32:27.060 MyApp[714] *** Assertion failure in -[NSApplication _commonBeginModalSessionForWindow:relativeToWindow:modalDelegate:didEndSelector:contextInfo:], AppKit.subproj/NSApplication.m:3057
2007-02-14 12:32:27.061 MyApp[714] Modal session requires modal window

Now the problem seems to be that it isn't loading the nib properly but why not? The nib files are "localised" and are in an English.lproj directory...



robbieduncan
Feb 14, 2007, 07:09 AM
What sort of class is this? If it's meant to the owner of the nib file then just make it an NSWindowController. Then nib loading just works. There is nothing to be gained from reinventing the wheel.

Eraserhead
Feb 14, 2007, 07:43 AM
What sort of class is this? If it's meant to the owner of the nib file then just make it an NSWindowController. Then nib loading just works. There is nothing to be gained from reinventing the wheel.

That now works, thanks! I owe you a beer. :)

robbieduncan
Feb 14, 2007, 07:45 AM
That now works, thanks! I owe you a beer. :)

Sweet :) The easy fixes are the best...