Fork me on GitHub

Programming Design Notes

Objective-C NSTimer

| Comments

NSTimer 的用法非常簡單,看以下例子。

*** 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];
}
相關書籍: iPhone SDK 3: Visual QuickStart GuideiPhone SDK 3 Programming: Advanced Mobile Development for Apple iPhone and iPod touch (Wiley)Beginning iPhone 3 Development: Exploring the iPhone SDK