Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return YES;
- }
- // Override to support editing the table view.
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (editingStyle == UITableViewCellEditingStyleDelete) {
- // Delete the row from the data source
- NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
- [context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];
- [self saveContext];
- }
- }
- - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
- return UITableViewCellEditingStyleDelete;
- }
- - (IBAction)setEditMode:(id)sender {
- [self.tableView setEditing:YES animated:YES];
- }
- - (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
- forRowAtIndexPath:(NSIndexPath *)indexPath {
- if(editingStyle == UITableViewCellEditingStyleDelete) {
- //Get the object to delete from the array.
- Coffee *coffeeObj = [appDelegate.coffeeArray objectAtIndex:indexPath.row];
- [appDelegate removeCoffee:coffeeObj];
- //Delete the object from the table.
- [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
- }
- }
Add Comment
Please, Sign In to add comment