Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

alexandergre

macrumors member
Original poster
Jul 28, 2009
58
0
Code:
-(IBAction)StartTheTimer:(id)sender{
	[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateCounter:) userInfo:nil repeats:YES];
}

- (void)updateCounter:(NSTimer *)theTimer {
	static int count = 5;
	count--;
	NSString *s = [[NSString alloc]
				   initWithFormat:@"%d", count];
	timeLeft.text = s;
	[s release];
	if(count==0)
	{
		timeLeft.text=@"done";
		//[COLOR="Red"][NSTimer invalidate];[/COLOR]
	}
	

	
}

If I uncomment [NSTimer invalidate] Then I get a warning. :(
: warning: 'NSTimer' may not respond to '+invalidate'
 
I figured it out:
Code:
-(IBAction)StartTheTimer:(id)sender{
	[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateCounter:) userInfo:nil repeats:YES];
}

- (void)updateCounter:(NSTimer *)theTimer {
	static int count = 10;
	count--;
	NSString *s = [[NSString alloc]
				   initWithFormat:@"%d", count];
	timeLeft.text = s;
	[s release];
	if(count==0)
	{
		[theTimer invalidate];
		timeLeft.text=@"done";
		
	}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.