我在我的 TableView 中实现了“滑动删除”选项,如下所示:
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()
}
}
在我的计时器实现之前它工作正常:
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()
}
编辑:
现在,滑动删除功能不起作用了。我滑动时没有附加内容。
我怎样才能使它再次工作?
最佳答案
更新
- 移除
updateTimer
中的reloadData
- 使用我的代码显示您的
行[j]["time"]
。
来源
如果你想显示你的计时器,你可以使用这个:
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"])"
}
}
}
关于swift - 滑动删除不适用于计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45344533/