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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-19-2009, 01:26 PM   #1 (permalink)
iOS Dev
 
Join Date: Aug 2009
Location: Chandigarh
Posts: 39
Jango is on a distinguished road
Send a message via Skype™ to Jango
Question How to stop NSTimer?

Hi,

I need to find a way to stop the NSTimer without invalidating it.

Cheers,
Jango is offline   Reply With Quote
Old 08-19-2009, 01:48 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

why
smithdale87 is offline   Reply With Quote
Old 08-19-2009, 01:56 PM   #3 (permalink)
Humbled Student
 
Dutch's Avatar
 
Join Date: Apr 2009
Location: Long Island, NY
Age: 32
Posts: 883
Dutch will become famous soon enough
Send a message via AIM to Dutch
Default

Quote:
Originally Posted by smithdale87 View Post
why
You read my mind!
Dutch is offline   Reply With Quote
Old 08-19-2009, 02:04 PM   #4 (permalink)
iOS Dev
 
Join Date: Aug 2009
Location: Chandigarh
Posts: 39
Jango is on a distinguished road
Send a message via Skype™ to Jango
Question

Quote:
Originally Posted by Dutch View Post
You read my mind!
I have this alarm app that activates the timer, in that invalidate works well.

The problem arises when I want to reset the timer before it(alarm) goes on.

invalidate what it does is it stops the receiver from ever firing again and requests its removal from its NSRunLoop object but when the timer is not being started in the first place, in that case invalidate is causing the app to quit.

Any suggestions???
Jango is offline   Reply With Quote
Old 08-19-2009, 02:55 PM   #5 (permalink)
Digital Assertion
 
drewag's Avatar
 
Join Date: Aug 2009
Posts: 268
drewag is on a distinguished road
Default

Quote:
Originally Posted by Jango View Post
I have this alarm app that activates the timer, in that invalidate works well.

The problem arises when I want to reset the timer before it(alarm) goes on.

invalidate what it does is it stops the receiver from ever firing again and requests its removal from its NSRunLoop object but when the timer is not being started in the first place, in that case invalidate is causing the app to quit.

Any suggestions???
Do you need it to be a timer that repeats? If not you can use:
Code:
[self performSelector:@selector(timerFunction) withObject:nil afterDelay:timeInSeconds];
then to stop it you can use:
Code:
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(timerfunction) object:nil];
There may be a way to do the same thing with a timer but I am not sure. Also it may not be pretty, but you could just use a BOOL for if the alarm actually goes off and just set that to false to cancel the alarm. Then inside the alarm function don't do anything if the bool is false.
__________________
Digital Assertion, LLC
Check out our iPhone apps:
Notecards: Great study tool for anytime anywhere!
Redirect: Addicting puzzle / action game!

Follow Digital Assertion on Twitter: DigAssertion

Follow me on Twitter: Andrew Wagner
drewag is offline   Reply With Quote
Reply

Bookmarks

Tags
invalidate, nstimer

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 317
13 members and 304 guests
chiataytuday, coolman, givensur, glenn_sayers, guusleijsten, ipodphone, jbro, mediaspree, mottdog, mtl_tech_guy, Punkjumper, vilisei, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,883
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:25 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0