Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView - how do I close row actions?

Tags:

uitableview

I've implemented tableView:editActionsForRowAtIndexPath:. In response to some of these actions, i want to snap the row action area back closed.

There doesn't seem to be an appropriate method on UITableViewRowAction. I've tried endEditing on both the table and table cell; I'm not sure what to try next.

How do I do snap the action area closed?

like image 971
Steven Fisher Avatar asked Oct 15 '14 00:10

Steven Fisher


3 Answers

If you do self.tableView.setEditing(false, animated: true), the user will be brought out of editing mode. I think what you want is you want to stay in editing mode but just dismissing the row action. So you can use the following code:

self.tableView.cellForRow(at: cellIndex)?.setEditing(false, animated: true) self.tableView.reloadData() // this is necessary, otherwise, it won't animate

like image 73
yohannes Avatar answered Oct 13 '22 21:10

yohannes


To close the edit actions you can either set the tableViews edit state:

tableView.editing = NO 

or set it with animation:

[tableView setEditing:NO animated:YES]
like image 35
kluver Avatar answered Nov 02 '22 09:11

kluver


Update for Swift 3

I've been looking for a way to do this using Swift 3, and I finally found it:

tableView.isEditing = false
like image 8
Ibrahim Avatar answered Nov 02 '22 07:11

Ibrahim