Ios 取消尾随滑动操作时如何添加操作(Swift 5)
在我的项目中,我使用trailingswipeactions为rowat func配置。我还可以在需要时使用selectRow func。如果我的单元格被选中,并且我在其上使用了滑动,然后我取消了它(从左向右滑动),则我的单元格不会再次被选中。我在哪里可以修复它(再次使用selectRow)Ios 取消尾随滑动操作时如何添加操作(Swift 5),ios,swift,uitableview,Ios,Swift,Uitableview,在我的项目中,我使用trailingswipeactions为rowat func配置。我还可以在需要时使用selectRow func。如果我的单元格被选中,并且我在其上使用了滑动,然后我取消了它(从左向右滑动),则我的单元格不会再次被选中。我在哪里可以修复它(再次使用selectRow) 您没有调用完成处理程序。根据API文档,有必要调用完成处理程序来指示操作是否成功 func tableView(_ tableView: UITableView, trailingSwipeActionsC
您没有调用完成处理程序。根据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
}
您可以使用:
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
}
如果您想获得平滑效果,也可以使用动画。谢谢您的回答。据我所知,如果deleteAction未完成,我可以使用“complete”作为标志再次选择行?在这里,No complete基本上是一个完成处理程序。完成处理程序作为参数传递给函数,然后在该函数完成时调用。请在这里阅读更多关于他们的信息。很抱歉,如果我隐藏了“滑动操作”菜单,我仍然不明白应该在何处再次使用selectRow。很抱歉,您先选择该行,然后再对其使用滑动?要执行刷卡,实际上不需要先选择它。不,我之所以突出显示该行是因为另一个原因。我创建了一个音乐播放器,这样我就可以显示现在正在播放的曲目。很好的答案正是我所需要的
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
}