Re: Using beginSheet
Re: Using beginSheet
- Subject: Re: Using beginSheet
- From: Hua Ying Ling <email@hidden>
- Date: Sun, 22 Jul 2001 09:25:19 -0400
- Organization: North Carolina State University
>
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:
That's exactly what happened, in my case it was because the window wasn't
loaded by "initWithWindowNibName", still trying to figure out why.
>
> 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:
That originally didn't add a modal session first. I added it later because
of a misleading error, "need modal window to create modal session", this
error was actually because one of the windows wasn't loaded by
"initWithWindowNibName".
>
>
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.
Yes in the end I got it to work by doing exactly what you suggested
creating a window in Interface Builder letting the app load the window for
me and I also had to use the didEndSheet selector.
Thanks for the help
~Hua Ying