问题
I have trailing swipe actions configured in my UITableView. The actions work correctly, but when an action removes the cell from the table, the swipe actions remain over the row that replaces the removed row. So it looks like the new current row is swiped.
And I think the swipe actions may actually transfer their attachment to that new row, I can't tell.
Is there some dismiss function I don't realize I need to call?
回答1:
For your contextual action, don't forget to set your completion handler to true or false based on if you completed the action or not:
let delete = UIContextualAction(style: .destructive, title: "Delete") { (myContext, myView, complete) in
//Did what you wanted to do
complete(true)
//Cancelled the action
complete(false)
}
This lets the UI update and remove the trailing or leading actions.
回答2:
Worked for me
let action = UIContextualAction(style: .normal, title: "View Details", handler: { (action, view, completionHandler) in
completionHandler(true)
})
This will closed the swipe action when you tap on it.
来源:https://stackoverflow.com/questions/51585935/trailing-swipe-actions-not-dismissing