Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSApplication endSheet: has no effect

Ok, this is really stumping me:

I create a modal sheet on a window as

-(IBAction) login: (id) sender {
[NSApp beginSheet:loginWindow 
   modalForWindow:window 
    modalDelegate:nil 
   didEndSelector:nil 
      contextInfo:nil];
}

and try to remove it with

-(IBAction) loginWindowCancelPressed:   (id) sender {
debugLog(@"cancel");
[NSApp endSheet:loginWindow];
}

but it remains.

I've checked all of the obvious things like IB connections and ensuring that window and loginWindow are present and in the normal state.

So, the question is: Am I missing something?

like image 497
tomwhipple Avatar asked Aug 26 '10 14:08

tomwhipple


2 Answers

You have to set up a delegate for the sheet. The delegate should implement a method with a signature like the following:

- (void)didEndSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;

(You can use a different name if you like, but it should accept the same parameters.)

You can do whatever you need to do in that method, but ultimately it should end with:

[sheet orderOut:self];

which will dismiss the sheet.

like image 194
mipadi Avatar answered Oct 05 '22 20:10

mipadi


See: Creating a Modal Dialog or Window in Cocoa Objective-c?

A delegate is not required. The following works for me to dismiss and allows calling it back later:

[NSApp endSheet: loginWindow];
[loginWindow orderOut:self];
like image 40
Noah Avatar answered Oct 05 '22 18:10

Noah