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 00:00:04 -0600
On Jan 14, 2006, at 8:38 PM, Ricky Sharp wrote:
I need a timer to always run during the lifetime of my
application. It runs about 10 times per second and is responsible
for executing the next command in a script file. I use this script
to test my app; basically simulates clicks on my controls along
with other activities.
Anyhow, I create/add the timer like this:
NSTimer* theTimer = [NSTimer timerWithTimeInterval:IIScriptInterval
target:self
selector:@selector(processNextCommand:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:theTimer
forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] addTimer:theTimer
forMode:NSModalPanelRunLoopMode];
Now then, my app has one and only one window (think kiosk). The
window's content changes over time. Whenever I need to display a
"dialog", I render the "dialog's" content in that same window and
then drop into a modal event loop via this:
int theModalValue = [NSApp runModalForWindow:[self contentWindow]];
But my timer never fires when I'm in the modal loop. This has me
baffled as that's what NSModalPanelRunLoopMode is supposed to be
for; to allow timers to run when in modal loops.
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.
___________________________________________________________
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