Reputation: 443
I have implement the option "Swipe to delete" in my TableView like this:
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView, commit editingStyle:
UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
rows.remove(at: indexPath.row)
runnerTableView.deleteRows(at: [indexPath], with: .fade)
runnerTableView.reloadData()
}
}
It works fine before the implementation of my Timer:
timer = Timer.scheduledTimer(timeInterval: 0.01, target: self,
selector:#selector(ViewController.updateTimer), userInfo: nil, repeats: true)
RunLoop.main.add(timer, forMode: RunLoopMode.commonModes)
func updateTimer () {
var j = 0
for _ in rows {
if (rows[j]["Playing"] as! Bool == true ) {
rows[j]["time"] = (rows[j]["time"] as! Double + 0.01) as AnyObject
}
j += 1
}
runnerTableView.reloadData()
}
EDIT:
Now, the swipe to delete just doesn't work. Nothing append when I swipe.
How can I do it works again?
Upvotes: 0
Views: 97
Reputation: 1473
Update
reloadData
in updateTimer
rows[j]["time"]
.Origin
If you want to show your timer, you can use this:
func updateTimer() {
var j = 0
for _ in rows {
if (rows[j]["Playing"] as! Bool == true ) {
rows[j]["time"] = (rows[j]["time"] as! Double + 0.01) as AnyObject
}
j += 1
}
for cell in tableView.visibleCells {
if let indexPath = tableView.indexPath(for: cell) {
cell.timeLabel.text = "\(rows[indexPath.row]["time"])"
}
}
}
Upvotes: 1