Search code examples
iosiphoneuitableviewcocoa-touchcell

Red minus sign is not appearing when I hit edit button


I did add this code to my viewDidLoad, the edit button showed up, but there is no minus button at the left side of the rows.

  self.navigationItem.leftBarButtonItem = self.editButtonItem;   

After swiping the row, the delete button shows up, but when I hit the edit button there is no minus sign.

What can cause the minus sign to not show up in my program?


Solution

  • Set your table view editing mode as,

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

    do the above in the action method of your edit button in navigation bar.

    Or just use,

    - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
        [super setEditing:editing animated:animated];
        [self.tableView setEditing:editing animated:animated];
    }
    

    If you want to show the delete button, you can implement the below code.

    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
    
         return UITableViewCellEditingStyleDelete;
    }
    

    For more details check the apple documentation