iOS UITableView滑动时NSTime停止重复利用RunLoop解决

当TableView滑动时会阻止Time的运行,其原因就是RunLoopMode的切换导致的。

ScrollView滑动时,runLoopMode为UITrackingRunLoopMode

time默认的RunLoopMode为kCFRunLoopDefaultMode

NSRunLoopCommonModes是RunLoopMode的集合

为了解决上面的问题,只需要如下做法

_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 120, self.view.frame.size.width, self.view.frame.size.height - 100) style:UITableViewStylePlain];
    _tableView.dataSource = self;
    _tableView.delegate =self;
    
    [self.view addSubview:_tableView];
    
    
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeMethod) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];


猜你喜欢

转载自blog.csdn.net/qqMCY/article/details/50888507