In a storyboard I have a root view controller with a button which triggers a 'Present as Popover' segue to a UINavigationController containing a UITableViewController. I want the nav controller to be present on both iPhone and iPad.
On an iPad, this works great in a popover.
On an iPhone, I get the modal presentation, so now I need an additional bar button item to dismiss the modal view. From watching the WWDC videos, I've attempted the following in the root view controller:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UIViewController *vc = segue.destinationViewController;
vc.popoverPresentationController.delegate = self;
}
- (void)dismissPopover {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (UIViewController *)presentationController:(UIPresentationController *)controller viewControllerForAdaptivePresentationStyle:(UIModalPresentationStyle)style {
UINavigationController *nvc = (UINavigationController *)controller.presentedViewController;
UIBarButtonItem *bbi = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(dismissPopover)];
nvc.topViewController.navigationItem.leftBarButtonItem = bbi;
return nvc;
}
I understand the -presentationController:viewControllerForAdaptivePresentationStyle: method should only get called when the UI is adaptive i.e. modal, however it doesn't get called at all, even when running as a modal on iPhone.