我已经为UITableViewCell实现左/右滑动
override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let closeAction = UIContextualAction(style: .normal, title: "Close", handler: { (ac:UIContextualAction, view: UIView, success:(Bool) -> Void) in
success(true)
})
closeAction.image = UIImage(named: "tick")
closeAction.backgroundColor = .purple
let config = UISwipeActionsConfiguration(actions: [closeAction])
return config
}
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let modifyAction = UIContextualAction(style: .normal, title: "Update", handler: { (ac:UIContextualAction, view: UIView, success:(Bool) -> Void) in
print("Update action ...")
success(true)
})
modifyAction.image = UIImage(named: "hammer")
modifyAction.backgroundColor = .blue
return UISwipeActionsConfiguration(actions: [modifyAction])
}
但是当我拖动一些东西后释放它时,单元格仍保留在最后一个位置(当我再次点击它时,它会向后移动)。有没有办法在将它拖动一些并释放后将单元移回初始位置?感谢