Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dismiss UITableViewRowAction

Tags:

ios

swift

I have a custom UITableViewRowAction set up and working. The only thing I can't work out is how to dismiss the UITableViewRowAction once an action has been selected. I'm sure I'm missing something really obvious. Here is my current setup:

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {      var moreRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "In", handler:{action, indexpath in         //Some code to execute here     });     moreRowAction.backgroundColor = UIColor(red: 0.298, green: 0.851, blue: 0.3922, alpha: 1.0)      return [moreRowAction]; } 

Thanks for any advice.

like image 574
User4 Avatar asked Oct 04 '14 22:10

User4


2 Answers

You dismiss the action in the handler which gets called when the action is tapped. The documentation describes the handler as follows

The block to execute when the user taps the button associated with this action. UIKit makes a copy of the block you provide. When the user selects the action represented by this object, UIKit executes your handler block on the app’s main thread.

Independently, I suppose you could just set the table views editing property to false.

tableView.setEditing(false, animated: true) 
like image 182
Mundi Avatar answered Sep 18 '22 05:09

Mundi


This works for me:

tableView.editing = NO;

like image 23
Mario Jaramillo Avatar answered Sep 21 '22 05:09

Mario Jaramillo