NSTimer won't fire.
NSTimer won't fire.
- Subject: NSTimer won't fire.
- From: zeichensprecher <email@hidden>
- Date: Thu, 2 Dec 2004 14:48:52 +0100
Hello everybody;
I want to fire a timer, but whatever I do, the timer gets _never_
fired, exept when I call [timer fire].
I searched everything and everywhere, but all the codesnippets I found
won't help.
I would greatly appreciate if anyone would answer, because I'm really
running out of options and TFM takes me nowhere either...
:(
/* ==== FIRE TIMER ===== /*
float fireTime = 2; // testingValue of ~2 seconds
NSDate* fireDate = [NSDate dateWithTimeIntervalSinceNow:fireTime];
// send timed message to self
NSTimer* noteOffTimer = [[NSTimer alloc] initWithFireDate:fireDate
interval:fireTime
target:self
selector:@selector(receiveTimedMsg:)
userInfo:nil repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:noteOffTimer
forMode:NSDefaultRunLoopMode];
[noteOffTimer release]; // gets retained by runLoop
if([noteOffTimer isValid]) {
NSLog(@"noteOffTimer will fire in @%f seconds \n time NOW: %@ \n time
FIRE: %@",
fireTime, [NSDate dateWithTimeIntervalSinceNow:0], [noteOffTimer
fireDate]);
// the timer is valid, becaue NSLog logs every time
//[noteOffTimer fire]; // tester if selector are O.K. (they are!)
// and this is most strange: if timer is fired from here, it is
received, if not, it never comes...
}
/* ==== RECEIVE TIMER ==== */
// timer receiver
-(void)receiveTimedMsg:(NSTimer*)timer {
NSLog(@"YEAHH!!! jipeee!!! just received timer!!!!");
// do other things here...
[timer invalidate];
}
/
/-----------------------------------------------------------------------
--
I have also tried (first):
[NSTimer scheduledTimerWithInterval:2
target:self
selector:@selector(receiveTimesMsg:)
userInfo:nil
repeats:NO];
// and _no_ adding to runLoop
... but the result was the same as above.
The timer is valid, fires on explicit command, but _never_ fires by
itself.
... I also tried adding the NSTimer* timer as instance var: no luck
either.
... then I tried firing from somewhere else. no luck either.
Thanks in advance for any suggestion!
Regards,
Michael.
_______________________________________________
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