How to delete table row in iPhone

I have a UITableView, and I want to give the user the ability to delete a row when he slides or clicks a finger on the row. I know an editing style that provides a circular red button with a -ve on it. But how to implement flicking style. I saw many applications using it, so the apple provides some kind of built-in delegate for it, or we need to write our own controller for it.

+5
source share
2 answers

To get a swipe effect, you need to implement a table view delegate

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 

swipe . , , , swipe .

:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  [tableView beginUpdates];    
  if (editingStyle == UITableViewCellEditingStyleDelete) {
    // Do whatever data deletion you need to do...
    // Delete the row from the data source
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationTop];   
  }       
  [tableView endUpdates];
}

, .

+32

, , . .

UPDATE: iPhoneCoreDataRecipes , , , .

, :

// If I want to delete the next 3 cells after the one you click
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  NSMutableArray* indexPaths = [NSMutableArray array];
  for (int i = indexPath.row + 3; i < indexPath.row + 3; i++)
  {
    [indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
  }

  [tableView beginUpdates];
  [tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
  [tableView endUpdates];
  [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

, , , . ... segfaults.

+2

All Articles