Nate Pinchot
Nate Pinchot

Reputation: 3318

Programmatically dismiss the "swipe to delete" button/state for UITableViewCell?

I'm working on an iPad app which has a UISplitView. The root view of the split view is a UITableView. When the split view is rotated portrait, the root view controller is displayed in a UIPopoverViewController (obviously this is standard practice).

The issue I'm having is, when iPad is in portrait rotation, if the user swipes to delete on the root view and then touches on the detail view, and then opens the root view again, the cell will still be in the same state showing the "delete" from the swipe gesture. This is not the expected behavior.

Currently I am calling reloadData on the table view in viewDidDisappear (after super) in the root view, which has the desired end result. Is there is a more efficient way to accomplish this?

Upvotes: 34

Views: 10080

Answers (2)

Matt Connolly
Matt Connolly

Reputation: 9857

And to animate it:

[tableView setEditing:NO animated:YES];

Upvotes: 6

Jörn Eyrich
Jörn Eyrich

Reputation: 5151

You could alternatively end the editing mode of the UITableView (probably also in viewDidDisappear).

self.tableView.editing=false;

Not sure if that's more efficient - more explicit perhaps.

Upvotes: 70

Related Questions