Monday, August 02, 2010

iPhone: Implement Swipe-to-Delete in UITableView

Make sure your controller is a delegate of your table view:

Implement this in your controller:

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

[tableView beginUpdates];

if (editingStyle == UITableViewCellEditingStyleDelete) {

/* delete your entry here */

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationFade];

}

[tableView endUpdates];

}



Also make sure that your method numberOfRowsInSection reflects the change in data.

0 Comments:

Post a Comment

<< Home