Question

I'm using swipe to delete for a custom cell. For one particular cell the swipe function should not work.

My custom cell displays "Add new values". When this is selected a few cells are added and when we swipe, delete option appears. What I want is that swipe function should not work for the "add new values" cell.

Was it helpful?

Solution

Check the cell type in tableView:canEditRowAtIndexPath: , and return false if it's of the type that you can't edit.

So in pseudo code

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
   NSInteger row = [indexPath row];
   // Check row type

   if(rowType==add_new_values_type) // YOU NEED TO WRITE THIS
   { 
     return false;
   }
   // Return YES - we will be able to delete the row
    return YES;
}

OTHER TIPS

You can try this:

   - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
 {
    switch (indexPath.row) 
    {
      case 0: break; //assuming that your add cell is 1

      default:
          return UITableViewCellEditingStyleDelete; // rest of them you can delete
          break;
    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top