December 2012
Intermediate to advanced
834 pages
27h
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:

Figure 4-5. Table view cells with indentation
-(UITableViewCellEditingStyle)tableView:(UITableView*)tableVieweditingStyleForRowAtIndexPath:(NSIndexPath*)indexPath{UITableViewCellEditingStyleresult=UITableViewCellEditingStyleNone;if([tableViewisEqual:self.myTableView]){result=UITableViewCellEditingStyleDelete;}returnresult;}-(void)setEditing:(BOOL)editinganimated:(BOOL)animated{[supersetEditing:editinganimated:animated];[self.myTableViewsetEditing:editinganimated:animated];}-(void)tableView:(UITableView*)tableViewcommitEditingStyle:(UITableViewCellEditingStyle)editingStyleforRowAtIndexPath:(NSIndexPath*)indexPath{if(editingStyle==UITableViewCellEditingStyleDelete){if(indexPath.row<[self.arrayOfRowscount]){/* First remove this object from the source */[self.arrayOfRowsremoveObjectAtIndex:indexPath.row];/* Then remove the associated cell from the Table View */[tableViewdeleteRowsAtIndexPaths:[NSArrayarrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationLeft];}}}
The tableView:editingStyleForRowAtIndexPath: ...
Read now
Unlock full access