iOS: UITableView – Swipe to delete row

On May 6, 2013, in iOS, Objective C, by Dipin Krishna

Swipe-to-Delete feature shows a “Delete” button when a user swipes horizontally across a row.

swipe to delete

To enable the swipe-to-delete feature of table views, you must implement the tableView:commitEditingStyle:forRowAtIndexPath: method.
Add the following code to enable the swipe-to-delete feature.

- (void)tableView:(UITableView *)tableView 
	commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
	forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //add code here to do what you want when you hit delete
        [itemArray removeObjectAtIndex:[indexPath row]];
        [tableView reloadData];
    }
}
Tagged with:  

Leave a Reply

*

Search