需要實現安排三個小事件,但是不用給每個單獨開一個功能。怎麼樣用NStimer
實現?
[NSTimer scheduledTimerWithTimeInterval:gameInterval
target:self selector:@selector(/* I simply want to update a label here */)
userInfo:nil repeats:NO];
你可以用上dispatch_after
,可以幫你實現和NSTimer和block執行類似的。
示例代碼:
int64_t delayInSeconds = gameInterval; // Your Game Interval as mentioned above by you
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
// Update your label here.
});