开发者

UIScrollView blocks run loop?

I implem开发者_如何学JAVAented a NSTimer(repeats) and UITableView on the same viewController.

Somehow, when I scroll through the tableView, the run loop seems to stop firing the NSTimer. The same goes for UITextView, which is also a subclass of UIScrollView.

May I know what is happening here?


The reason that the timer stops firing is that the run loop switches to UITrackingRunLoopMode during scrolling and the timer is not added by default to that mode. You can do that manually when you start the timer:

NSTimer *timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];
NSRunLoop *runloop = [NSRunLoop currentRunLoop];
[runloop addTimer:timer forMode:NSRunLoopCommonModes];
[runloop addTimer:timer forMode:UITrackingRunLoopMode];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜