ios – 允许UITableViewCell更新内容,即使滚动

参见英文答案 >
UILabel updating stops during scrolling UIScrollView                                    5个

我有一个UITableView包含一个包含时间(最近毫秒)的自定义UITableViewCell.滚动时,直到滚动停止后才会更新时间文本.我知道这可能是大多数人所希望的默认行为,但我希望单元格在滚动时不断更新.有没有办法做到这一点?我在文档中找不到任何内容.

该单元使用NSTimer以每秒30次的递归方式调用更新时间函数.此函数更新单元格上的UILabel.

最佳答案 查看
this answer以获得深入阅读.长话短说明您需要将计时器设置为以共同模式运行.这样它会更新,而其他东西正在采用UI线程.这是我使用我的方式:

downloadAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:.05 target:self selector:@selector(animateDownloadButtons) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:downloadAnimationTimer forMode:NSRunLoopCommonModes];
点赞