I am using a SplitViewController and Core Data. My Master view is a simple TableView like the SplitViewController template. I have these three methods:
- (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;
}
I thought this would be enough to show the delete button when I swipe the row to delete it. What happens now is if you swipe it the first time and only the first time, the delete button shows up then disappears. If I swipe again, nothing happens. I need to restart the simulator in order for it to show again. On my TableViewCell, I have a UILabel and a UITextField. I thought maybe the UITextField would be intercepting the swipe, but I resized them so they are only on the left half just in case.
Edit:
So I still haven't figured out why this happens. I thought I would add an edit button to test if the tableView setEditing: even gets called. So in my action method, I do:
- (IBAction)setEditMode:(id)sender {
[self.tableView setEditing:YES animated:YES];
}
This method does get called, but the tableView never gets in editing mode. All of this is in a subclass of UITableViewController. Is there something else i'm missing? Thanks!