Error Message: endSheet: requires a non-nil sheet

Discussion in 'Mac Programming' started by rien333, Sep 1, 2012.

  1. rien333 macrumors regular

    Joined:
    Jun 29, 2010
    Location:
    The Netherlands
    #1
    Hi,

    I'm having some trouble with custom sheets in Cocoa. Basically, I've set up an custom sheet with a button that closes it. Every time I close the sheet I get the following error message: endSheet:returnCode: requires a non-nil sheet
    without the sheet closing.

    The structure of my project is kind of like this:
    It contains nib file named Input.xib with some unimportant stuff on it, except for a button that triggers a close action via an object named InputController (A class that controls the stuff in the window). The Files Owner's class is set to OutputController, which is sort of the the main controller class.

    The stripped down .m file of InputController looks like this:

    Code:
    
    #import "InputController.h"
    #import "OutputController.h"
    
    @implementation InputController
    
    - (id)init
    {
        self = [super init];
        if (self) {
            outputController = [[OutputController alloc] init];
        }
        return self;
    }
    
    - (IBAction)close:(id)sender { // The close button action
        
        
        [outputController closeInputWindow];
    
    }
    
    @end
    
    Then we have the OutputController class, which is a Controller class for an output window, which is the window the sheet is displayed on.

    In the OutputController .h file I have set up an IBOutlet @property of an NSWindow named inputSheet. It is connected to Window in the Input.xib file via the Files Owner (The Output Controller).

    The stripped down .m file looks like this:

    Code:
    #import "OutputController.h"
    #import "InputController.h"
    
    @synthesize inputSheet = _inputSheet;
    
    - (void)activateInputWindow {
        if (!_inputSheet) {
            [NSBundle loadNibNamed:@"Input" owner:self];
        }
        
        [NSApp beginSheet:_inputSheet modalForWindow:[NSApp keyWindow] modalDelegate:self didEndSelector:nil contextInfo:nil];
        
    }
    
    - (void)closeInputWindow {
        
        [NSApp endSheet:_inputSheet]; // This produces the error message
        [_inputSheet close];
        _inputSheet = nil;
      
    }
    
    @end
    
    So… why is my _inputSheet nil when endSheet: is called?

    P.S: I sort of did what the documentation said: https://developer.apple.com/library...ts.html#//apple_ref/doc/uid/20001290-BABFIBIA
     
  2. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    I don't know, but I would set a breakpoint in all the places where _inputSheet is changed or where you think it would be changed. And with .xib files the problem is quite often that you managed to create two objects when you think you should have one.
     
  3. rien333 thread starter macrumors regular

    Joined:
    Jun 29, 2010
    Location:
    The Netherlands

Share This Page