I am playing with using a sheet in my app.
I have a little test project setup to find my way.
I did have this code working:
- (IBAction)activateSheet:(id)sender {
if (!_sheet)
[NSBundle loadNibNamed:@"Sheet" owner:self];
[NSApp beginSheet:self.sheet
modalForWindow:[[NSApp delegate] window]
modalDelegate:self
didEndSelector:NULL
contextInfo:NULL];
}
but the loadNibNamed method is deprecated.
So I substitute this:
- (IBAction)activateSheet:(id)sender {
if (!_sheet)
NSLog(@"1");
[[NSBundle mainBundle] loadNibNamed:@"Sheet" owner:self topLevelObjects:nil];
[NSApp beginSheet:self.sheet
modalForWindow: [[NSApp delegate] window]
modalDelegate:self
didEndSelector:NULL
contextInfo:NULL];
}
The sheet opens fine. But if I press save or cancel, I get a EXC_BAD_ACCESS exception:
int main(int argc, const char * argv[])
{
return NSApplicationMain(argc, argv);
}
UPDATE - This is a breeze with 10.9:
- (IBAction)activateSheet:(id)sender {
if (!_sheet)
[[NSBundle mainBundle] loadNibNamed:@"Sheet" owner:self topLevelObjects:nil];
[[[NSApp delegate] window] beginSheet:self.sheet completionHandler:nil];
}
- (void)endSheet:(NSWindow *)sheetWindow returnCode:(NSModalResponse)returnCode {
[sheetWindow orderOut:self];
}
- (IBAction)save:(id)sender {
[self doSave];
result = 1;
[self endSheet:self.sheet returnCode:result];
}
- (IBAction)cancel:(id)sender {
result = 0;
[self endSheet:self.sheet returnCode:result];
}