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
I found that the accepted answer doesn't correctly display a "done" button when in Compact mode (e.g. iPhone) but remain as popover in Regular mode (e.g. iPad).
The following code is the bare minimum to make this work – place these in the presenting view controller class.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UIViewController *dest = segue.destinationViewController;
dest.popoverPresentationController.delegate = self;
}
- (UIViewController *)presentationController:(UIPresentationController *)controller viewControllerForAdaptivePresentationStyle:(UIModalPresentationStyle)style {
UIViewController* presentedViewController = controller.presentedViewController;
if ([controller isKindOfClass:[UIPopoverPresentationController class]] && style == UIModalPresentationFullScreen) {
UINavigationController* navCtrl = [[UINavigationController alloc] initWithRootViewController:presentedViewController];
UIBarButtonItem *bbi = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(dismiss:)];
presentedViewController.navigationItem.rightBarButtonItem = bbi;
return navCtrl;
}
return presentedViewController;
}
-(IBAction)dismiss:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
Notice the three differences with the accepted answer:
adaptivePresentationStyleForPresentationController: