Ios 对于UITableview,删除不起作用 MyTableviewController
我想把图像(垃圾)而不是文本,图像显示,但删除行动时,没有发生试图删除该行。我不知道我做错了什么。如何删除我的tableview行?有人能帮我吗?提前感谢。您应该删除在Ios 对于UITableview,删除不起作用 MyTableviewController,ios,swift,Ios,Swift,我想把图像(垃圾)而不是文本,图像显示,但删除行动时,没有发生试图删除该行。我不知道我做错了什么。如何删除我的tableview行?有人能帮我吗?提前感谢。您应该删除在editActionsForRowAt中传递的indexath处的单元格,如下所示: func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { let
editActionsForRowAt
中传递的indexath处的单元格,如下所示:
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let remove = UITableViewRowAction(style: .default, title: " ") { action, indexPath in
tableView.beginUpdates()
tableView.deleteRows(at: [IndexPath(row: index, section: 0)], with: .left)
tableView.endUpdates()
}
remove.backgroundColor = UIColor(patternImage: UIImage(named: "delete")!)
return [remove]
}
它将删除该行,但与数组中的数据不一致。您还可以从特定索引处的数组中删除项,然后调用
tableView.reloadData()
从tableView中删除行后,您需要重新加载行
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let remove = UITableViewRowAction(style: .default, title: " ") { action, indexPath in
tableView.deleteRows(at: [IndexPath(row: index, section: 0)], with: .left)
self.tableView.reloadRows(at: [IndexPath], with: .fade)
}
remove.backgroundColor = UIColor(patternImage: UIImage(named: "delete")!)
return [remove]
}
您的删除操作中没有任何代码。是的,我在出错的地方得到了它。
[indepath(row:index,section:0)]
可以更改为[indepath]
您需要从数据源数组中删除元素,否则会出现异常
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let remove = UITableViewRowAction(style: .default, title: " ") { action, indexPath in
tableView.deleteRows(at: [IndexPath(row: index, section: 0)], with: .left)
self.tableView.reloadRows(at: [IndexPath], with: .fade)
}
remove.backgroundColor = UIColor(patternImage: UIImage(named: "delete")!)
return [remove]
}