@interface className
{
NSTimer * timer;
}
@property (nonatomic, retain) NSTimer * timer;
@end
@implementation className
@synthesize timer;
...
-(void) applicationDidFinishLaunching : (UIApplication *) application {
timer = [NSTimer scheduledTimerWithInterval: 1.0 target:self selector:@selector(targetMethod:) userInfo:nil repeats: YES];
}
//define the targetmethod
-(void) targetMethod: NSTimer * theTimer {
NSLog(@"Me is here at 1 minute delay");
}
..
@end
Refer to http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/Timers/Articles/usingTimers.html
Thank you very much for posting this. This simple example helped me more than the gobs of documentation in the API reference.
ReplyDeleteThanks for this example! I'd just like to point out though that the call is actually scheduledTimerWithTimeInterval, not scheduledTimerWithInterval... Not sure if your method is an old deprecated version, but thought I'd let you know :)
ReplyDeleteHi Every Body, i made an application of Quiz where i show question and there answers so my problem is first time when question launch on screen and i set timer to 2 sec to show answers of questions one by one and it works fine but next when i pass next question then this timer does not work it show answers very rapidly
ReplyDeleteThis method i call on Pass button click event
[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(changeAnswerOption) userInfo:nil repeats:YES];