从 UISplitViewControllers 主视图到详细视图进行模态呈现

make modally presentation from UISplitViewControllers primary view to detail view

我在 UISplitViewController 的主视图控制器中有一个加号按钮,我想在我的详细视图中以模态方式呈现一些东西,就像苹果在 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];
}

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

- (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(或 "horizontally compact devices")上忽略 modalPresentationStyle,因此您的 "IS_IPAD" 检查可能是多余的。

希望对您有所帮助!