【发布时间】:2014-10-06 04:04:50
【问题描述】:
在情节提要中,我有一个带有按钮的根视图控制器,该按钮触发“作为弹出框呈现”到包含 UITableViewController 的 UINavigationController 的 segue。我希望导航控制器同时出现在 iPhone 和 iPad 上。
在 iPad 上,这在弹出窗口中效果很好。
在 iPhone 上,我得到了模态显示,所以现在我需要一个额外的条形按钮项来关闭模态视图。通过观看 WWDC 视频,我在根视图控制器中尝试了以下操作:
- (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;
}
我知道 -presentationController:viewControllerForAdaptivePresentationStyle: 方法应该只在 UI 自适应(即模态)时被调用,但它根本不会被调用,即使在 iPhone 上作为模态运行时也是如此。
【问题讨论】:
标签: ios objective-c uikit uistoryboard