Re: Having trouble with NSTimer and runModalForWindow [Solved]
Re: Having trouble with NSTimer and runModalForWindow [Solved]
- Subject: Re: Having trouble with NSTimer and runModalForWindow [Solved]
- From: Ricky Sharp <email@hidden>
- Date: Sun, 15 Jan 2006 10:28:30 -0600
On Jan 15, 2006, at 12:00 AM, Ricky Sharp wrote:
Found the culprit...
I started out with a small sample project where all code lived in
the application controller (delegate). All worked well.
Comparing things to my app, I had a singleton object (IIScript)
maintain all aspects of the script to include the creation of the
timer. So the target of
timerWithTimeInterval:target:selector:userInfo:repeats: was the
instance of IIScript and not the app controller.
I moved the timer logic to my app controller and now all works as
expected. I don't see anything in the docs that put any
restrictions on what a target can be. But using the app controller
as the target works, and that's a perfect solution for me.
Actually, this explanation is bogus as the real problem has been
found :)
In my app, the implementation of my timer method used to be:
- (void)processScript_II:(NSTimer*)aTimer
{
[script_II processNextCommand_II];
}
But processNextCommand_II could invoke a command that would drop me
in a local modal loop. Thus, control was never being returned to
processScript_II so it could finish. That's why my timer never fired
again until the modal loop was terminated.
I've now changed things to tell the run loop to process the script
command in the future and thus allow the current event to finish:
- (void)processScript_II:(NSTimer*)aTimer
{
static NSArray* theModesArray = nil;
if (theModesArray == nil)
{
theModesArray = [[NSArray
arrayWithObject:NSDefaultRunLoopMode] retain];
}
[[NSRunLoop currentRunLoop] performSelector:@selector
(processNextCommand_II:) target:script_II
argument:self order:0 modes:theModesArray];
}
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
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