LOLXDXPLOL
LOLXDXPLOL

Reputation: 611

setEditing method delete button doesn't work

In my UIViewController, I have an UITableView which contains different cells with saved contents by using the NSUserDefaults. I also have a custom UIBarButtonItem which causes the UITableView to enter and leave editing mode.

This all works, but the problem is when I tap the round red button and on the right side of the cell appears the delete button, the delete button doesn't work... I can tap on it as much as I want but the cell does not get deleted.

@IBAction func EditListButton(sender: UIBarButtonItem) {
    if ShoppingListTable.editing {
        ShoppingListTable.setEditing(false, animated: true)
        self.EditListButton.title = "Edit"
    } else {
        ShoppingListTable.setEditing(true, animated: true)
        self.EditListButton.title = "Done"
    }
}

Upvotes: 1

Views: 484

Answers (1)

Guillaume Algis
Guillaume Algis

Reputation: 11016

Use UITableViewDataSource's tableView:commitEditingStyle:forRowAtIndexPath: to detect a tap on the delete button.

Then in the implementation delete the row from your data source (NSUserDefaults in your case).

So in your tableView's dataSource (ie. in the class you implemented numberOfSectionsInTableView: for example), add your custom implementation of tableView:commitEditingStyle:forRowAtIndexPath: where you delete the underlying data.

Upvotes: 1

Related Questions