October 2013
Intermediate to advanced
1053 pages
28h 7m
English
You want your application users to be able to delete rows from a table view easily.
Implement the tableView:editingStyleForRowAtIndexPath:
selector in the delegate and the tableView:commitEditingStyle:forRowAtIndexPath:
selector in the data source of your table view:
-(UITableViewCellEditingStyle)tableView:(UITableView*)tableVieweditingStyleForRowAtIndexPath:(NSIndexPath*)indexPath{returnUITableViewCellEditingStyleDelete;}-(void)setEditing:(BOOL)editinganimated:(BOOL)animated{[supersetEditing:editinganimated:animated];[self.myTableViewsetEditing:editinganimated:animated];}-(void)tableView:(UITableView*)tableViewcommitEditingStyle:(UITableViewCellEditingStyle)editingStyleforRowAtIndexPath:(NSIndexPath*)indexPath{if(editingStyle==UITableViewCellEditingStyleDelete){/* First remove this object from the source */[self.allRowsremoveObjectAtIndex:indexPath.row];/* Then remove the associated cell from the Table View */[tableViewdeleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationLeft];}}
The tableView:editingStyleForRowAtIndexPath:
method can enable deletions. It is called by the table view, and its
return value determines what the table view allows the
user to do (insertion, deletion, etc.). The tableView:commitEditingStyle:forRowAtIndexPath: method carries out the user’s requested deletion. The latter method is defined in the delegate, but its functionality is a bit ...
Read now
Unlock full access