在我的项目中,我使用了trailingSwipeActionsConfigurationForRowAt函数。我也会在需要的时候使用selectRow函数。如果我的单元格被选中,我使用了swipe,然后我取消了它(从左向右滑动),我的单元格不会再次被选中。我可以在哪里修复它(再次使用selectRow )?
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let deleteAction = UIContextualAction(style: .destructive, title: "") { [weak self] (contextualAction, view, boolValue) in
guard let self = self else { return }
self.deleteRow(at: indexPath)
}
deleteAction.image = UIImage(systemName: "trash")
let swipeActions = UISwipeActionsConfiguration(actions: [deleteAction])
return swipeActions
}发布于 2021-04-29 06:50:11
您可以使用:
func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?) {
//Get the cell's indexPath (be aware of the optional argument and threat it the way you want)
let cell = tableView.cellForRow(at: indexPath!)
//Use the cell to the changes you need
}如果你想获得一个平滑的效果,你也可以使用动画。
发布于 2020-10-09 18:14:54
您不会调用完成处理程序。根据API文档,需要调用完成处理程序来指示操作是否成功。
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let deleteAction = UIContextualAction(style: .destructive, title: "") { _, _, complete in
// remove object from your array..
self.arrayName.remove(at: indexPath.row)
//reload the table to avoid index out of bounds crash..
self.tableView.deleteRows(at: [indexPath], with: .automatic)
complete(true)
}
deleteAction.image = UIImage(named: "trash")
let configuration = UISwipeActionsConfiguration(actions: [deleteAction])
configuration.performsFirstActionWithFullSwipe = true
return configuration
}https://stackoverflow.com/questions/64276660
复制相似问题