Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 09-18-2009, 12:37 AM   #13 (permalink)
djhash
Registered Member
 
Join Date: Sep 2009
Posts: 4
djhash is on a distinguished road
Default

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.
djhash is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,277
Threads: 93,954
Posts: 402,303
Top Poster: BrianSlick (7,971)
Welcome to our newest member, AppTroll
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:43 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.