tags:

views:

167

answers:

1

I have a view with navigation bar control on the top. The view is in the second level with a "back" button is displayed on the left by default. In my view class, I added a default navigation edit button on the right:

self.navigationbarItem.rightButtonItem = self.editButtonItem;

with this line of code, an edit button is on the right side, and when it is clicked, the view (table view) becomes editable with delete mark on the left for each row. After that, the edit button's caption becomes "done". All those are done by the default edit button built in the navigation control, I think.

I would like to add an add button the left, or replace "back" button when edit is clicked. I guess I have to implement some kind of delegate in my view class. This would provide a place to plug in my code to add the add button on the left when edit button is clicked, and to restore "back" button back when the done button is clicked. If so, what's the delegate? Or is there any other way to achieve it?

+1  A: 

I do it like this (in my table view controller):

    editButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered target:self action:@selector(toggleEditing)];
    editButton.possibleTitles = [NSSet setWithObjects:@"Edit", @"Done", nil];
    self.navigationItem.rightBarButtonItem = editButton;


- (void)toggleEditing {
    // Keep track of whether your editing or not here
    // and show/hide the 'add' button accordingly
}
Zoran Simic
It looks like you add a customized button. How about the default behavior of delete marks? Any way to set the table view in edit mode?
David.Chu.ca
Set the table view in edit mode with its setEditing:animated: method.
glorifiedHacker