iPhone - Add "Add" Button when Edit button is selected in UITableView

ios, iphone, objective-c, uitableview

Solution

This is easy enough. Override the `setEditing:animated:` method of your view controller. This is called when the Edit/Done button is toggled (assuming you are using the standard `editButtonItem` from `UIViewController`).

In this method you create an "add" button and make it the left bar button item. This will hide the back button. Remove the "add" button and the back button will reappear.

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];

    if (editing) {
        // Add the + button
        UIBarButtonItem *addBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addAction:)];
        self.navigationItem.leftBarButtonItem = addBtn;
    } else {
        // remove the + button
        self.navigationItem.leftBarButtonItem = nil;
    }
}

Problem

i have a table view in my application which shows some items. when i click on one item, a new table view appears (with navigation controller: push). So at the top of the Table view there is now the navigationcontroller with the automatic "back" arrow to get back. i have the "edit" button enabled on the right side. Now i want when i tap on the edit button, the Back button should disappear and a "+" add button should be there instead of the back button. Is this possible? Or it is possible to get the Edit and Add button on the screen at the same time? thanks

Original source