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 06-02-2010, 12:14 PM   #1 (permalink)
Banned
 
Join Date: Jun 2010
Posts: 91
maxk77 is on a distinguished road
Default NSTimer Reset Not Working

Hi, my nstimer reset button is not working and when i click on it, it will reset the label to 2:00 but when i press the start button again it will carry on as if the reset button was never pressed.

here is my code:
Code:
- (void)countDownOneSecond
{
    seconds--;
	
	int currentTime = [timerLabel.text intValue];
	int newTime = currentTime - 1;
    int displaySeconds = !(seconds % 60) ? 0 : seconds < 60 ? seconds : seconds - 60;
    int displayMinutes = floor(seconds / 60);
	
    NSString *time = [NSString stringWithFormat:@"%d:%@%d", 
					  displayMinutes,
					  [[NSString stringWithFormat:@"%d", displaySeconds] length] == 1 ? @"0" : @"",
					  displaySeconds
					  ];
	timerLabel.text = time;
	if(seconds == 0)
    {
		[timer invalidate];
    }
	
}

- (void)startOrStopTimer
{
	if(timerIsRunning){
		[timer invalidate];
		[startOrStopButton setTitle:@"Start" forState:UIControlStateNormal];
	} else {
		timer = [[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDownOneSecond) userInfo:nil repeats:YES] retain];
		[startOrStopButton setTitle:@"Stop" forState:UIControlStateNormal];
	}
	
	timerIsRunning = !timerIsRunning;
}

- (void)resetTimer
{
	[timer invalidate];
	[startOrStopButton setTitle:@"Start" forState:UIControlStateNormal];
	[timer invalidate];
	timerLabel.text = @"2:00";
}
maxk77 is offline   Reply With Quote
Old 06-02-2010, 12:21 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

You never reset "seconds"
harrytheshark is offline   Reply With Quote
Old 06-02-2010, 12:23 PM   #3 (permalink)
Banned
 
Join Date: Jun 2010
Posts: 91
maxk77 is on a distinguished road
Default

how do i do that?

Quote:
Originally Posted by harrytheshark View Post
You never reset "seconds"
maxk77 is offline   Reply With Quote
Old 06-02-2010, 12:25 PM   #4 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

Code:
seconds = 120;
harrytheshark is offline   Reply With Quote
Old 06-02-2010, 12:26 PM   #5 (permalink)
Banned
 
Join Date: Jun 2010
Posts: 91
maxk77 is on a distinguished road
Default

merci

Quote:
Originally Posted by harrytheshark View Post
Code:
seconds = 120;
maxk77 is offline   Reply With Quote
Old 02-01-2011, 03:37 AM   #6 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 43
chandaboy is on a distinguished road
Default

you have to reset the second also, so that the timer will start again.
ie,.
seconds = 120;
chandaboy is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, nstimer, reset, xcode

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: 349
13 members and 336 guests
ajay123123, Anwerbl, Arty Tales, ashaman64, baja_yu, ChrisYates, HemiMG, mini998, mottdog, newDev, Objective Zero, oceanlablight, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,878
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 07:59 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0