首页 > 解决方案 > 重新加载表格视图并向右滑动删除

问题描述

我每 0.25 秒重新加载一次表格视图,因为我有一个计时器应用程序,但是当我从右向左滑动时删除按钮不会留在那里,因为我正在重新加载表格视图。

我该如何解决?

标签: iosswiftuitableviewtimer

解决方案


无需更新可见单元格reloadtableView相反,循环遍历每个调用 update 方法的可见单元格:

// Example custom cell class
class MyCustomCell: UITableViewCell {
    func updateTimeLabel() {
        // code to update time label
    }
}

在计时器方法中:

for case let cell as MyCustomCell in tableView.visibleCells {
    cell.updateTimeLabel()
}

您的updateTimeLabel方法可能需要Date时间标签的当前值或新值等数据,因此请传递更新标签所需的数据。


推荐阅读