I have simple master and detail view controllers connected with two segues, one for “show detail” and one for “add new”.
- “Show detail” segues to the detail view controller with setEditing:NO.
- Tap “+” (add icon) segues to the detail view controller with setEditing:YES
iOS 5.1: “+” works as I expect, the detail page is in edit mode and editingStyleForRowAtIndexPath fires to show the insert and delete indicators.
iOS 6.0: the “+” makes the transition to the detail page but editingStyleForRowAtIndexPath never fires. Other code that is in setEditing:YES gets executed. didSelectRowAtIndexPath does fire (delegate = self).
Once on the detail page edit mode works as expected in both cases.
Any ideas?
// Master.m
if([[segue identifier] isEqualToString:@"NewRecipe"]) {
DetailViewController *detailViewController = [segue destinationViewController];
// stuff
detailViewController.recipe = r;
detailViewController.delegate = self;
detailViewController.editing = YES;
}
// Detail.m
-(void)setEditing:(BOOL)flag animated:(BOOL)animated {
if (flag) {
[self.tableView setEditing:flag animated:YES];
[self.tableView beginUpdates];
// the row does get added
[self.tableView insertRowsAtIndexPaths:@[pathToAdd] withRowAnimation:UITableViewRowAnimationAutomatic];
// datasource gets updated here
[self.tableView endUpdates];
....
}
}
I figured it out. I don’t know why this is the fix, I hope this does not replace bad code with worse code.
For iOS 6 I needed the detailViewController to make a call to a delegate method to determine whether to setEditing:YES.