Trailing swipe actions not dismissing

白昼怎懂夜的黑 提交于 2019-12-07 16:45:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!