*** timer 先在 header 檔案定義。
NSTimer *timer;
- (void)startTimer {相關書籍:
timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(printHelloWorld) userInfo:nil repeats:YES];
}
- (void) printHelloWorld
{
printf("hello World");
}
- (void) stopTimer{
[timer invalidate];
}