UISplitViewController 内的 UITabBarController 内的 UINavigationController 以模态方式呈现在 iPhone 上 [英] UINavigationController inside a UITabBarController inside a UISplitViewController presented modally on iPhone

查看:16
本文介绍了UISplitViewController 内的 UITabBarController 内的 UINavigationController 以模态方式呈现在 iPhone 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UISplitViewController,其中包含一个 UITabBarController 作为主视图.这个 UITabBarController 包含一个 UINavigationController.详细视图也包含一个 UINavigationController.

I'm having a UISplitViewController that contains a UITabBarController as master view. This UITabBarController contains a UINavigationController. The detail view contains a UINavigationController as well.

在 iPad 上,这可以正常工作.show detail segue 在详细视图上显示导航控制器内的图像视图.

On the iPad this works as expected. The show detail segue presents the imageview within the navigation controller on the detail view.

另一方面,在 iPhone 上,我希望 show detail segue 将详细视图推送到主视图的导航控制器的堆栈上.但实际上它是在主视图上以模态方式呈现的.

On the iPhone on the other hand I expected that the show detail segue pushes the detail view on the stack of the navigation controller of the master view. But actually it is presented modally over the master view.

当从情节提要中删除 UITabBarController 并直接在主视图中使用 UINavigationController 时,这是可行的.

When removing the UITabBarController from the storyboard and using the UINavigationController directly in the master view this works.

有人知道如何在 iPhone 上的主 UINavigationController 堆栈上显示详细视图吗?

Has anybody an idea how I could present the detail view on the stack of the master's UINavigationController on an iPhone?

推荐答案

我想出了如何将细节放在主人的 UINavigationController 上,而不是在 UITabBarController 上模态地呈现它.

I figured out how to put the detail on to the master's UINavigationController instead of presenting it modally over the UITabBarController.

使用 UISplitViewControllerDelegate 方法

- splitViewController:showDetailViewController:sender:

如果 UISplitViewController 折叠,获取主导航控制器并将详细视图推送到此导航控制器:

In case the UISplitViewController is collapsed get the masters navigation controller and push the detail view onto this navigation controller:

- (BOOL)splitViewController:(UISplitViewController *)splitViewController
   showDetailViewController:(UIViewController *)vc
                     sender:(id)sender {
    NSLog(@"UISplitViewController collapsed: %d", splitViewController.collapsed);

    // TODO: add introspection
    if (splitViewController.collapsed) {
        UITabBarController *master = (UITabBarController *) splitViewController.viewControllers[0];
        UINavigationController *masterNavigationController = (UINavigationController *)master.selectedViewController;

        // push detail view on the navigation controller
        //[masterNavigationController pushViewController:vc animated:YES];
        // push was not always working (see discussion in answer below), use showViewController instead
        [masterNavigationController showViewController:vc sender:sender];

        return YES;
    }

    return NO;
}

这篇关于UISplitViewController 内的 UITabBarController 内的 UINavigationController 以模态方式呈现在 iPhone 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆