[iOS] NSTimer

How to use the NSTimer.

-(IBAction)startBtnPressed
{
	//start timer
	[NSTimer scheduledTimerWithTimeInterval:1.0f 
									 target:self 
								   selector:@selector(timerHandler:) 
								   userInfo:nil 
									repeats:YES];
}
-(IBAction)stopBtnPressed
{
	if (currentTimer != nil) {
		[currentTimer invalidate]; //stop timer
		currentTimer = nil;
		[currentTimer release];
		count = 0;
	}
}

-(void)timerHandler:(NSTimer *) timer
{
	currentTimer = timer;
	count += 1;
	NSLog(@"%d", count);
	label.text = [NSString stringWithFormat:@"count is %d", count];
}

I don’t understand how to use @selecter.
But I understand that it needs function name with colon (ex foo:).

Comments are closed.