UITableView 在滚动视图时停止更新内容?

UITableView stops updating content while scrolling through view?

我有一个 UITableView,它可以正常工作并且可以正常更新。我还有一个计时器,用于更新每个 UITableView 标签和进度视图,当用户滚动 table 视图时,它会停止 updating/refreshing UITableView 中的内容(标签和进度视图),直到它们完成滚动.

除了内容未更新外,我发现当用户滚动时整个应用程序挂起。我有两个计时器,我在两个计时器中都放置了 print 语句,但是当用户滚动时都不打印。我一直无法找到 swift 或 swift 2 解决方案。

这与 Swift 完全无关。

您可能使用默认方法安排了 NSTimer,这导致以滚动时不触发的方式将其添加到运行循环中。您需要使用 NSRunLoopCommonModes 模式将其添加到主运行循环中。

例如

let timer = NSTimer(timeInterval: 1.0, target: self, selector: #selector(update), userInfo: nil, repeats: false)
NSRunloop.mainRunLoop().addTimer(timer, forMode: NSRunloopCommonModes)