UISplitViewController 内的 UITabBarController 内的 UINavigationC

2023-06-13移动开发问题
10

本文介绍了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 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7

[ios.cocos2d+box2d]如何禁用自动旋转?
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)...
2024-08-12 移动开发问题
7