Question

I have a view which has it's own navigation bar and one tableview. I want to edit & delete item in that table view. I have placed and edit button on the navigation bar like this.

self.navItem.leftBarButtonItem = self.editButtonItem;

And also have one method like this.

- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if(editingStyle == UITableViewCellEditingStyleDelete) {

        //Get the object to delete from the array.
        //Delete the object from the table.
        [self.tblView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}

But when I am clicking on that button, none of the item in tableview turns with that red mark icon. Just caption of edit button changes to "Done".

What should be the problem?

Was it helpful?

Solution

Is this a UIViewController, or a UITableViewController? It would appear (from self.tblView in the attached code) that you're using a standard UIViewController. In this case, you have to implement setEditing:animated: in your view controller, which, in turn, should call that in your table view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top