Graphics Programs Reference
In-Depth Information
UITableViewDataSource protocol. (This message is sent to the ItemsViewCon-
troller . Keep in mind that while the BNRItemStore is the where the data is kept,
the ItemsViewController is the table view's “data source.”)
When tableView:commitEditingStyle:forRowAtIndexPath: is sent to the
data source, two extra arguments are passed along with it. The first is the UIT-
ableViewCellEditingStyle , which, in this case, is UITableViewCellEdit-
ingStyleDelete . The other argument is the NSIndexPath of the row in the table.
In ItemsViewController.m , implement this method to have the BNRItemStore
remove the right object and to confirm the row deletion by sending the message de-
leteRowsAtIndexPaths:withRowAnimation: back to the table view.
- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
// If the table view is asking to commit a delete command...
if (editingStyle == UITableViewCellEditingStyleDelete)
{
BNRItemStore *ps = [BNRItemStore sharedStore];
NSArray *items = [ps allItems];
BNRItem *p = [items objectAtIndex:[indexPath row]];
[ps removeItem:p];
// We also remove that row from the table view with an animation
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
}
Build and run your application, create some rows, and then delete a row. It will disappear.
Try out some of the different row animations!
Search WWH ::




Custom Search