Re: Stacking run loops
Re: Stacking run loops
- Subject: Re: Stacking run loops
- From: Ricky Sharp <email@hidden>
- Date: Thu, 16 Dec 2004 07:38:56 -0600
On Thursday, December 16, 2004, at 05:56AM, patrick machielse <email@hidden> wrote:
>Op 16-dec-04 om 5:51 heeft Ricky Sharp het volgende geschreven:
>
>> Here are two methods I've implemented in my app controller:
>>
>> - (void)runDialogScreen:(int)aScreenID
>> {
>> [self pushScreen:aScreenID];
>>
>> CFRunLoopRun();
>>
>> [self popScreen];
>> }
>>
>> Here, pushScreen: will load a nib for the given screen ID. That nib's
>> owner is a controller for that particular screen (in this case the
>> about dialog).
>>
>> After the nib is loaded, the main window's content view is replaced
>> with the content view from a well-named panel object in the nib (the
>> about dialog UI).
>>
>> The controller for the about dialog then has an IBAction for
>> okButtonPressed. In that method, I call the app controller's
>> endDialogScreen:
>>
>> - (void)endDialogScreen
>> {
>> CFRunLoopStop ([[NSRunLoop currentRunLoop] getCFRunLoop]);
>> }
>
>I can't comment directly on your situation, but I've found that you
>shouldn't mix CFRunLoop and NSRunLoop. Especially, I could not get the
>construct:
>
> CFRunLoopStop ([[NSRunLoop currentRunLoop] getCFRunLoop]);
>
>to stop a RunLoop started with CFRunLoopRun(). The setup that finally
>worked for me was:
>
> CFRunLoopRef runLoop = CFRunLoopGetCurrent();
> CFRunLoopRun();
>
> ...
>
> CFRunLoopStop(runLoop);
>
>Don't know why, but this worked for me.
Interesting.
I decided to look at different implementations and started out by trying runModalForWindow. But that failed in that while I could click on my UI items (or use the keyboard), my IBAction methods were never called.
Ultimately, I decided to do things manually with my own local event loop:
modalLoopDone = NO; // iVar
do
{
NSAutoreleasePool* thePool = [[NSAutoreleasePool alloc] init];
NSEvent* theEvent = [NSApp nextEventMatchingMask:NSAnyEventMask
untilDate:[NSDate distantPast] inMode:NSEventTrackingRunLoopMode dequeue:YES];
[NSApp sendEvent:theEvent];
[thePool release];
}
while (!modalLoopDone);
I then set the modalLoopDone flag when needing to exit the loop.
This approach works a-ok, so I'll live with it for now. I do want to spend more time though on an NSRunLoop approach as that should have worked. Need to also dig into why runModalForWindow also failed. One thing that comes to mind is that my window is at a window level of NSNormalWindowLevel + 2. My blanking (backdrop) windows are at NSNormalWindowLevel + 1. This was done to work around problems with Expose.
--
Rick Sharp
Instant Interactive(tm)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden