Reputation: 1174
I am reloading table view every 0.25 seconds as I have a timer app, but the delete button when I swipe from right to left won't stay there because I am reloading the table view.
How do I fix this?
Upvotes: 0
Views: 390
Reputation: 154563
There is no need to reload
the tableView
to update the visible cells. Instead, loop over the visible cells calling the update method on each one:
// Example custom cell class
class MyCustomCell: UITableViewCell {
func updateTimeLabel() {
// code to update time label
}
}
In the timer method:
for case let cell as MyCustomCell in tableView.visibleCells {
cell.updateTimeLabel()
}
Your updateTimeLabel
method might need data such as the current Date
or the new value for the time label, so pass it what it needs to update the label.
Upvotes: 1
Reputation: 1427
a start of solution could be to observe swipe events on tableview thanks to :
optional func tableView(_ tableView: UITableView, willBeginEditingRowAtIndexPath indexPath: NSIndexPath)
in this func you stop the reload func
and in :
optional func tableView(_ tableView: UITableView, didEndEditingRowAtIndexPath indexPath: NSIndexPath)
you restart your reload func
Upvotes: 0