Search code examples
iphoneios4uitoolbar

How to invoke built-in "Edit" and "Add" functionality in UIToolbar custom buttons


I have added uitoolbar in uinavigationcontroller using IB (by selecting the check box - "show toolbar"). I used IB since this was easy to add flexible spacing bar buttons (I did not want to deal with spacing code programmatically). My issue is that I want to invoke the built-in edit and add functionality for the 2 toolbar buttons I added. I know that in the navigation bar I can use the following code and it will invoke this functionality

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:nil];

Above code takes care of the "Edit view", where the table view items are shown with a delete button next to them.

How can I achieve the same for the buttons that I added to the toolbar? I am using Xcode 4. Please point me to some code examples.


Solution

  • self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
    initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(callEdit)];
    

    In callEdit method.

    -(void)callEdit {
         [self.tableView setEditing:YES];
    }