4

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?

Jonathan Tuzman
  • 11,568
  • 18
  • 69
  • 129
  • What is the data source for that `UITableView` ? Is it based on an array or `NSFetchedResultsController` ? Have you remove that particular data from the data source ? – user1046037 Jul 30 '18 at 06:09
  • The data source is of type Realm Results. The row does get removed from the table view, the problem is that the swipe actions are still showing after the row is gone. – Jonathan Tuzman Jul 30 '18 at 11:39

2 Answers2

12

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.

Daniel
  • 8,794
  • 4
  • 48
  • 71
Scott Ward
  • 121
  • 3
8

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.

Rajasekhar Pasupuleti
  • 1,598
  • 15
  • 22