Loading second nib file

Discussion in 'Mac Programming' started by Eraserhead, Feb 14, 2007.

  1. macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #1
    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...
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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.
     
  3. thread starter macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #3
    That now works, thanks! I owe you a beer. :)
     
  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Sweet :) The easy fixes are the best...
     

Share This Page