I've got a UIButton on the TableViewCell of my app, which I'm trying to use to delete the cell. (I know I should use standard swipe-to-delete, but it doesn't fit with my UX and this will be much better). I've used the following code to try to delete the cell. I get no warnings about any of it in Xcode, but when I run the app and try to delete a cell, I get a SIGTRAP crash and the cell is not deleted, as well as the log says "deleting (null)" opposed to deleting (ItemName). Does anyone have any suggestions on how I could fix this issue? A huge thanks to anyone that can help out. I've been struggling with this same issue for more than a week, and I cannot figure it out at all.
Code:
- (IBAction)deleteButtonTapped:(id)sender {
UIButton *button = (UIButton *)sender;
UIView *backView = (UIView *)button.superview;
UITableViewCell *cell = (UITableViewCell *)backView.superview;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
Item *itemToDelete = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSLog(@"Deleting (%@)", itemToDelete);
[self.managedObjectContext deleteObject:itemToDelete];
[self.managedObjectContext save:nil];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self performFetch];