Uitableview Edit Button

Discussion in 'iPhone/iPad Programming' started by iPhoneSpain, Dec 8, 2009.

  1. macrumors newbie

    Joined:
    Sep 27, 2009
    #1
    Hi,

    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

    johnnyjibbs

    Joined:
    Sep 18, 2003
    Location:
    London, UK
    #2
    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:

    Code:
    - (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:

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

Share This Page