Re: modal sheet not understood
Re: modal sheet not understood
- Subject: Re: modal sheet not understood
- From: "Rob Napier" <email@hidden>
- Date: Fri, 14 Mar 2008 12:24:29 -0400
If it waited for the sheet to close, then the rest of your application
would hang with the beach ball. Most of your program runs in a single
thread. If your method does not terminate, very little else in your
application will work. Just because you're modal for one window
doesn't mean you want the entire application to hang waiting for the
user. This is why Cocoa relies heavily on callbacks such as the
didEndSelector: below. Your program can go about it business (doing
many things that aren't actually in your code), and when the user is
done, the code you want will be run.
Remember the magic rule of Cocoa: There is no magic. If a control
lights up, there was code somewhere that made that happen, and it had
to get a chance to run. The code that makes the buttons work is not
deeply different from the code that you write yourself. As you get
used to it, this is a wonderful fact.
-Rob
On Fri, Mar 14, 2008 at 12:16 PM, Hans van der Meer
<email@hidden> wrote:
> I thought to implement an open panel on my main window and expected it
> to wait for the dismissal of the sheet. It seems that actually the
> events are out of the inendedorder. What is wrong with the following
> code? Why didn't it wait for the sheet being closed?
>
> // Put up the sheet for and retrieve the return value.
> [panel beginSheetForDirectory:nil
> file:nil
> types:nil
> modalForWindow:aWindow
> modalDelegate:self
> didEndSelector:@selector(openSheetDidEnd:returnCode:contextInfo:)
> contextInfo:nil];
>
> // If we have a file path the data will be read.
> NSLog(@"directly after beginSheetForDirectory");
> NSString *filePath = [[panel filenames] objectAtIndex:0];
> .....
>
> - (void) openSheetDidEnd:(NSOpenPanel *)panel
> returnCode:(int)returnCode contextInfo:(void *)contextInfo; {
> NSLog(@"directly inside openSheetDidEnd");
> if (NSOKButton == returnCode)
> NSLog(@"chosen sheet %@", [[panel filenames] objectAtIndex:0]);
> else
> NSLog(@"sheet cancelled");
> }
>
> This called somewhere starting at ...ForWindow[NSApp mainWindow] ->
> aWindow
>
> The output shows the wrong order of events:
> 2008-03-14 .. directly after beginSheetForDirectory
> 2008-03-14 .. *** -[NSCFArray objectAtIndex:]: index (0) beyond bounds
> (0)
> 2008-03-14 .. directly inside openSheetDidEnd
> 2008-03-14 .. chosen sheet /Users/hans/Projects/Cocoa/Railfence/testdata
>
> Hans van der Meer
>
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
--
"Those who would give up essential liberty to purchase a little
temporary safety, deserve neither liberty nor safety." -- B. Franklin,
Printer
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden