- 问题:
项目的UITableViewCell中有Timer更新cell的进度条,而UITableView在滚动的时候这个动画就会静止,会引起一些问题(比如显示不准确)。
这个问题困扰了我一阵子也是最近才想到可能的解决方案,查找了一些资料发现UIScrollView在滚动的时候run loop是
UITrackingRunLoopMode
,原因在于UIScrollView在滚动的时候会block一切不在它自己的run loop mode对象。 -
解决方案:
将Timer加入到runloop中
NSTimer *timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(sel) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
- 关于UITrackingRunLoopMode
The mode set while tracking in controls takes place. You can use this mode to add timers that fire during tracking.
Available in iOS 2.0 and later.