gpt4 book ai didi

swift - 滑动删除不适用于计时器

转载 作者:行者123 更新时间:2023-11-28 15:25:21 24 4
gpt4 key购买 nike

我在我的 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()
}

编辑:

enter image description here

现在,滑动删除功能不起作用了。我滑动时没有附加内容。

我怎样才能使它再次工作?

最佳答案

更新

  1. 移除 updateTimer 中的 reloadData
  2. 使用我的代码显示您的行[j]["time"]

My workable way

来源

如果你想显示你的计时器,你可以使用这个:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com