gpt4 book ai didi

swift - 在 UIContextualAction 回调中调用 tableView.selectRow 时没有效果

转载 作者:行者123 更新时间:2023-11-30 10:43:10 25 4
gpt4 key购买 nike

UIContextualAction 回调中调用 selectRow(at:animated:scrollPosition:) 时,没有任何变化:指定的行不会变成灰色。

这是我可以编写的显示该问题的最简单的代码:

override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let deleteAction = UIContextualAction(style: .destructive, title: "Delete") { _, _, callback in
tableView.selectRow(at: IndexPath(item: 0, section: 0), animated: true, scrollPosition: .none)
callback(true)
}

return UISwipeActionsConfiguration(actions: [deleteAction])
}

我尝试了很多变体:

  • 正确执行删除操作(更新模型,然后使用 deleteRows() 更新 TableView )
  • 不为选择操作设置动画
  • 使用 .normal 操作而不是 .destroy 操作
  • 将回调代码的各个部分分组到 tableView.performBatchUpdates() block 中
  • performBatchUpdates() 调用内部和外部以不同的顺序调用所有这些方法
  • 以某种方式使用 CATransaction.setCompletionBlock() 等待删除动画结束
  • 在主队列上调度选择操作,让它稍后执行

一切都没有成功。

最佳答案

在删除操作的特定情况下,您可以实现 tableView(tableView: cell: indexPath:) 委托(delegate)方法,并在那里执行选择;不过,请务必检查单元格是否只是简单地滚动到屏幕外。

func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if cellWasBeingDeleted(cell) { // your own implementation
tableView.selectRow(at: IndexPath(item: 0, section: 0), animated: true, scrollPosition: .none)
}
}

关于swift - 在 UIContextualAction 回调中调用 tableView.selectRow 时没有效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56363293/

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