从 UISplitViewController 主视图到详细信息视图进行模式演示



我在UISplitViewController的主视图控制器中有一个加号按钮,我想在我的详细信息视图中以模式方式显示一些内容,就像Apple在iPad的地址簿中添加新联系人时所做的那样。我已经尝试了一切,但什么都没有。我设法做到了,但是当我尝试将我呈现的视图控制器嵌入到 UINavigation 控制器中时,我呈现的控制器会覆盖全屏。有什么建议吗?这是我的代码:

UINavigationController *navController = [self.splitViewController.viewControllers lastObject]; DetailTableViewController *controller = (DetailTableViewController *)navController.topViewController;

controller.definesPresentationContext = YES;
controller.providesPresentationContextTransitionStyle = YES;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
EditTableViewController *etvc = (EditTableViewController *)[storyboard instantiateViewControllerWithIdentifier:@"EditTableViewController"];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:etvc];
etvc.patient = patient;
if (IDIOM == IPAD)
{
    etvc.modalPresentationStyle = UIModalPresentationCurrentContext;
    [controller presentViewController:nav animated:YES completion:nil];
} else {
    [self presentViewController:nav animated:YES completion:nil];
}

我刚刚通过创建一个自定义 segue 成功地解决了这个问题,其实现是:

- (void)perform
{
    UIViewController *ctrl = self.sourceViewController;
    UIViewController *dest = self.destinationViewController;
    dest.modalPresentationStyle = UIModalPresentationCurrentContext;
    [ctrl presentViewController:dest animated:YES completion:nil];
}

通过在要覆盖它的模式视图上从我的详细信息视图控制器调用此 segue 来查看我想要的行为。

我认为您的代码在哪里失控:

etvc.modalPresentationStyle = UIModalPresentationCurrentContext;

我认为应该是:

nav.modalPresentationStyle = UIModalPresentationCurrentContext;

虽然我还没有测试过。

请注意,Apple 文档建议在 iPhone(或"水平紧凑型设备")上忽略 modalPresentationStyle,因此您的"IS_IPAD"检查可能是多余的。

希望这有帮助!

最新更新