Uitableview Edit Button

Discussion in 'iOS Programming' started by iPhoneSpain, Dec 8, 2009.

  1. macrumors newbie

    Sep 27, 2009

    I would like to put a button that is able to do the same that the edit button that is provided by every uitableview:

    self.navigationItem.leftBarButtonItem = self.editButtonItem;

    So I´ve created a uibarbuttonitem with its ibaction method but...what do I have to write inside that ibaction method to have the same functionality that I have when I press the edit button?

    Thanks in advance!!!
  2. macrumors 68030


    Sep 18, 2003
    London, UK
    You should just need to toggle set editing to on (or off).

    Depending on if your view controller is a table view controller or not, you should just be able to do something like the following:

    - (IBAction)customEditButtonWasPressed:(id)sender {
        if (self.editing) {
            // Toggle editing off as it is already on
            [self setEditing:NO animated:YES];
        } else {
            // Toggle editing on
            [self setEditing:YES animated:YES];
    You may need to actually set the editing of the table view itself instead if you are not using a tableview controller, eg:

    [self.mainTableView setEditing:YES animated:YES];

Share This Page