Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Eraserhead

macrumors G4
Original poster
Nov 3, 2005
10,434
12,250
UK
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.

Code:
-(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

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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

macrumors G4
Original poster
Nov 3, 2005
10,434
12,250
UK
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. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.