Quote:
However, after that functionality you'll need to invalidate the timer if it's currently valid and re-add the timer to the run loop.
That might seem odd to do... I mean, the code that's running here is in a method that is called when the timer fires (at which point the timer should not be valid). And why re-add it to the run loop? If you don't, you'll find that your application will lock up when you touch and hold and then move. I'm not sure I understand exactly why myself.
|
The reason is being when an NSTimer is invalidated, it is released from memory. So when you try to invoke isValid. The code is looking at a nil pointer or memory location and tells you "this method is not available" and crash.
What you should do is retain the NSTimer after you create the NSTimer
PHP Code:
touchTimer = [NSTimer scheduledTimerWithTimeInterval:delay target:self selector:@selector(touchHeld:) userInfo:nil repeats:YES];
[touchTimer retain];
Then you don't need to re-add the timer to the loop.
Thank you though for your post. It works like a charm. (with the exception of the repeated timer initialization which as I shown is not necessary)
DjHash
P.S. I wont take credit for this.. I found the solution here..
Re: NSTimer
I hope this helps anyone looking for touches held.