diff --git a/iOS/MonsterCards/Views/LibraryViewController.m b/iOS/MonsterCards/Views/LibraryViewController.m index e3b28fa..b392348 100644 --- a/iOS/MonsterCards/Views/LibraryViewController.m +++ b/iOS/MonsterCards/Views/LibraryViewController.m @@ -73,4 +73,20 @@ return cell; } +#pragma mark - UITableViewDelegate + +- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView +trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath { + UIContextualAction *action = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:NSLocalizedString(@"Delete", @"Command to delete an object.") handler:^(UIContextualAction *action, __kindof UIView *sourceView, void (^completionHandler)(BOOL actionPerformed)) { + Monster *monster = [self.allMonsters objectAtIndex:indexPath.row]; + [self->_context deleteObject:monster]; + [self->_context save:nil]; + self.allMonsters = [self->_context executeFetchRequest:[Monster fetchRequest] error:nil]; + [self.tableView reloadData]; + }]; + + UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:[NSArray arrayWithObject:action]]; + return config; +} + @end