Re: Using beginSheet
Re: Using beginSheet
- Subject: Re: Using beginSheet
- From: j o a r <email@hidden>
- Date: Sat, 21 Jul 2001 01:43:31 +0200
On fredag, juli 20, 2001, at 10:40 , Hua Ying Ling wrote:
I'm trying to create a sheet for a window but I keep getting a error
"Modal session requires modal window". What am I doing wrong in the
code snipplet below?
When I get this message it is usually because I have misplaced my
window - not hooked up properly in IB or released or something. Make
sure that both your windows are available! And if you are still learning
how to deal with windows and sheets, it is usually easier to create them
in IB, then programmatically like you do in your example here:
NSWindowController *newWindow = [[NSWindowController alloc]
initWithWindowNibName: @"AddGroupDialog"];
NSModalSession session = [NSApp
beginModalSessionForWindow:[newWindow window]];
[NSApp runModalSession:session];
[NSApp beginSheet:[newWindow window]
modalForWindow:mainWindow
modalDelegate: self
didEndSelector: @selector(didEndAddGroupSheet)
contextInfo: NULL];
[NSApp endModalSession:session];
When I see this code I'm a bit curious why you manually add a modal
session? Aren't sheets automatically modal? Try only this:
NSWindowController *newWindow = [[NSWindowController alloc]
initWithWindowNibName: @"AddGroupDialog"];
[NSApp beginSheet:[newWindow window]
modalForWindow:mainWindow
modalDelegate: self
didEndSelector: @selector(didEndAddGroupSheet)
contextInfo: NULL];
Also notice the sheet doesn't block the execution of your code, so you
cannot end it right after opening it in the code - or else it will
disappear as soon as you have opened it... You will have to end the
modal session / sheet in the action method the buttons in your sheet, or
in the didEndSelector specified method.
I've also read that the didEndSelector must match this type of selector
"didEndSheet:returnCode:contextInfo:" - ie. that number of parameters
and types, but I'm not sure that it is mandatory - keep it in mind if
you run into problems with that later though.
Regards,
j o a r