Resetting Edit button when no more items to delete


At the very end of the chapter, the Edit and + buttons are added to the ItemsViewController’s UINavigationBar to replace the earlier Edit and New buttons. However, there was a slight bug, or at least an anomaly IMO. If you’re in Edit mode, and you delete the last item, you stay in Edit mode. If you subsequently add an item without pressing Done, and go back to the ItemsViewController, you’ll still be in Edit mode. To fix this I added the following code at the end of ItemsViewController commitEditingStyle function.

        // Quit edit mode if no more items
        if (items.count == 0) {
            [self.tableView setEditing:NO animated:YES];
            [self setEditing:NO];


I also added the code above, without the if clause, at the very top of addNewItem. So now I get out of edit mode once my last item is deleted, and every time I add a new item.


[self setEditing:NO];

Should be sufficient.