My cocoa program has a save feature, which when user selected the saving destination, I'll have to bring up another NSPanel, to display some sort of status (ie. how long it will take to finished saving the file. Here is my code:
- (IBAction)savePressed:(id)sender {
__block NSSavePanel *saveDlg = [NSSavePanel savePanel];
// Enable options in the dialog.
[saveDlg setCanCreateDirectories:YES];
[saveDlg setAllowedFileTypes:[NSArray arrayWithObject:@"zip"]];
[saveDlg setCanSelectHiddenExtension:YES];
[saveDlg beginSheetModalForWindow:self.window completionHandler:^ (NSInteger result) {
if (result == NSOKButton) {
[self triggerNSPanel];
}
saveDlg = nil;
}];
}
- (void) triggerNSPanel {
if (!self.myPanel)
self.myPanel = [[NSPanel alloc] init];
[NSApp beginSheet:self.myPanel modalForWindow:self.window modalDelegate:nil didEndSelector:nil contextInfo:nil];
....
}
so once the NSSavePanel is disappeared (ie. ok is pressed), my NSPanel shows up for like 1/2 second, then it's gone, even I didn't call NSApp endSheet
Could be a problem that you call beginSheet from within the completion handler. There might be some cleanup after its invocation that kills your second sheet. Try sending triggerNSPanel via performSelector:afterDelay (delay can be 0, so it's trigger right in the next run loop round).