ios - NSTimer 与 UITableView

标签 ios objective-c uitableview

我有带有“开始”按钮的 UIView、带有我的 NSTimer 时间的 UILabel 和带有时间记录的 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
                                         selector:@selector(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
                                         selector:@selector(tick)
                                         userInfo:nil
                                          repeats:YES];

 [[NSRunLoop mainRunLoop] addTimer:myTimer forMode:NSRunLoopCommonModes];

关于ios - NSTimer 与 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24624497/

相关文章:

android - 非标准不支持的图像格式可以在移动 ios/android 应用程序中使用吗

ios - 将 iPhone 降级以进行测试

ios - 创建自定义顺序全局调度队列

ios - 每个部分应该返回多少行?

Swift:重新激活披露指示器上的点击手势

ios - 如何在 iOS 中使用 JBLineChart 绘制和自定义两条线?

iphone - NSDictionary 扁平化层次结构

ios - 在 UIImageView 的圆形图像中选择一个随机点

ios - 如何测试 NSMutableArray 中是否有 _NSCFConstantString?

java - 表格标题边框旧的uitable matlab