UIScrollView blocks run loop?

牧云@^-^@ 提交于 2019-12-19 10:30:32

问题


I implemented 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?


回答1:


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];


来源:https://stackoverflow.com/questions/7551411/uiscrollview-blocks-run-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!