0

I’d like to prevent a custom UITableViewCell from swiping to show the red Delete button. I can disable this on the UITableView, but I’ve not seen any existing questions that allow this to be done within the cell class, meaning I don’t need to do it on every table that uses that cell.

Can I disable this (without disabling editing entirely, I have a custom pann-able overflow) directly inside the cell class?

Luke
  • 9,512
  • 15
  • 82
  • 146

4 Answers4

3

Just use:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return indexPath.row != THE_ROW_YOU_WANT_TO_STOP;
}
CW0007007
  • 5,681
  • 4
  • 26
  • 31
1

Try to override - (void)setEditing: animated: method in the following way:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:NO animated:NO];
}
Sviatoslav Yakymiv
  • 7,887
  • 2
  • 23
  • 43
1

You need to implement editingStyleForRowAtIndexPath and perform your test there.

If there is only one cell that will have this pannable overflow and you know which row, you could define a constant and test for that, like so:

#define kPANNABLE_OVERFLOW_CELL_ROW  7

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ( indexPath.row == kPANNABLE_OVERFLOW_CELL_ROW )
    return UITableViewCellEditingStyleNone;
}

If you will have multiple, arbitrary cells that need this treatment, you'll need to handle it a bit differently.

Inside

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // create your table view cell
    if ( _Your_table_view_cell_is_the_pannable_overflow_type_ ) {
        cell.editingStyle = UITableViewCellEditingStyleNone;
    }
}
Rayfleck
  • 12,116
  • 8
  • 48
  • 74
1
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellEditingStyleNone;
}

Try above code it just disable the delete button from tableview cell swipe.

Edit: hiding button from cell go here

iPhone UITableView - Delete Button

Community
  • 1
  • 1
Jasmin
  • 794
  • 7
  • 18