工作,我必須實現「刷卡刪除」我的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()
}
編輯:
現在,要刪除的滑動功能不起作用。當我滑動時沒有附加內容。
我該怎麼辦呢?
1.我複製你的代碼,它的工作原理。 2.我實現你的計時器,它的工作原理。 你在'updateTimer'中做了什麼? – Codus
你不應該重新加載你的'tableview'! – Codus
@coded updateTimer的函數? – pierreafranck