我有带有“开始”按钮的UIView
,带有我的UILabel
时间的NSTimer
和带有时间记录的UITableView
。
问题是当我滚动tableview
-NSTimer
冻结时,为什么我可以使它们异步工作?
我的代码:
- (IBAction)startTimer {
_startButton.hidden = YES;
_stopButton.hidden = NO;
isRun = YES;
UIBackgroundTaskIdentifier bgTask = UIBackgroundTaskInvalid;
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
myTimer = [NSTimer scheduledTimerWithTimeInterval:0.01f
target:self
selectorselector(tick)
userInfo:nil
repeats:YES];
}
- (void)tick {
_timeSot++;
sot++;
/*some code*/
myTime = [NSString stringWithFormat"%@:%@:%@", minStr, secStr, sotStr];
[_timeLabel setText:myTime];
}
将myTimer
添加到NSRunLoopCommonModes
:
myTimer = [NSTimer scheduledTimerWithTimeInterval:0.01f
target:self
selectorselector(tick)
userInfo:nil
repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:myTimer forMode:NSRunLoopCommonModes];
关于ios - NSTimer与UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24624497/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |