Show Add button after Edit button is clicked?
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 edit开发者_如何学Pythonable 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?
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
}
精彩评论