Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS Swift TableView edit action for row at index path

I would like to know if there is an option to close the editing menu in the table view (as shown in the screenshot) which we get when we swipe to right. I want the menu to close as soon i select an option, in my case it does not close even when i select any one of the option. It closes only when i select anywhere on the screen.

Below is my code which im using

    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    
}

func tableView(tableView: UITableView!, canEditRowAtIndexPath indexPath: NSIndexPath!) -> Bool {
    return true
}

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]?
{
    let update = UITableViewRowAction(style: .Normal, title: "Update") { action, index in
        print("update")
    }
    let delete = UITableViewRowAction(style: .Default, title: "Delete") { action, index in
        print("Delete")
       
    }
    return [delete, update]
} 

enter image description here

like image 501
Kanan Jarrus Avatar asked Oct 30 '22 06:10

Kanan Jarrus


1 Answers

You need to just reload the particular cell and it's close the option.

For that you can use following code may this solve your problem.

self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top)

Also you can use

self.tableView.setEditing(false, animated: true)

Happy coding.

like image 87
Nimit Parekh Avatar answered Nov 08 '22 06:11

Nimit Parekh