Re: Modal sheet / dialog + thread == main app thread hangs ?
Re: Modal sheet / dialog + thread == main app thread hangs ?
- Subject: Re: Modal sheet / dialog + thread == main app thread hangs ?
- From: Marc Wandschneider <email@hidden>
- Date: Sun, 18 Oct 2009 14:06:10 +0800
>From the NSApplicationDocumentation:
"abortModal must be used instead of stopModal or stopModalWithCode:
when you need to stop a modal event loop from anywhere other than a
callout from that event loop. In other words, if you want to stop the
loop in response to a user’s actions within the modal window, use
stopModal; otherwise, use abortModal. For example, use abortModal when
running in a different thread from the Application Kit’s main thread
or when responding to an NSTimer that you have added to the
NSModalPanelRunLoopMode mode of the default NSRunLoop."
So, I learned something today. Nice.
thanks,
marc.
2009/10/18 Marc Wandschneider <email@hidden>:
> I'm in the midst of debugging an extremely unusual problem, and I was
> wondering if anybody might have any insight into what might be going
> wrong:
> In a controller class from a NIB, I take an NSPanel I from that same
> NIB, and then show it app modally on an NSWindow (that was created by
> hand in code):
>
> [[NSApplication sharedApplication] beginSheet: myPanel
> modalForWindow: window
> modalDelegate: self
> didEndSelector:
> @selector(sheetDidEnd:returnCode:contextInfo:)
> contextInfo: nil];
> [[NSApplication sharedApplication] runModalForWindow: myPanel];
>
>
> now, when the "finish button is clicked", i run some code to disable
> some buttons an fire off a thread to make sure the user input is valid
> (i have to validate with a remote service). This thread is fired from
> a separate validator object I create:
>
> * setEnabled NO on a few controls
> * setHidden NO on a control
>
> // validator object
> validateInfo: (NSDictionary *)parms notify: (SEL)notifySelector
> onObject: (id)notifyObject
> {
> // build up data with parms and notify info
> [[NSThread detachNewThreadSelector: @selector(remotevalidate:)
> toTarget: self withObject: data];
> }
>
>
> next, when the validation is finished, the validator notifies my
> controller object:
>
> [notifyObject performSelectorOnMainThread: notifySelector
> withObject: results waitUntilDone: NO];
>
>
>
> and then my controller object, in the method that the validator object
> calls, kills the dialog:
>
> - (void)validationComplete: (id)data
> {
> [[NSApplication sharedApplication] stopModal];
> [createTwitterPanel orderOut: nil];
> [[NSApplication sharedApplication] endSheet: createTwitterPanel
> returnCode: NSOKButton];
> }
>
>
> My problem: the top runModalForWindow does not exit until some system
> event is sent to the window that was showing the dialog. trying to
> move, resize, or do anything to the window, or otherwise switching
> away from the application suddenly causes method to exit and execution
> to continue. no amount of waiting seems to help, otherwise, however.
>
> An even further, more interesting clue is that the dialog has two
> controls, a WebView and a TextField. Even if I restart things by
> clicking on the window, TABbing between the two controls remains
> screwed up — it simply never works again.
>
> I've tried changing validationComplete: to instead post a notification
> to the main thread, and I've also played with the waitUntilDone on the
> performSelectorOnMainThread method, all to no effect.
>
> Any ideas? Things I should try looking at?
>
> Thanks,
> marc.
>
_______________________________________________
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