2011-07-09 49 views
11

我的窗口RootViewController的是一个UINavigationController 然后..在这个导航控制器的RootViewController的,我弹出一个模式的看法(一的UITabBarController)如何消除“两段旋转”警告?

是这样的:

UIWindow 
->UINavigationController 
-->MyFirstViewController<--In this class I run following code 
[self.navigationController presentModalViewController:tabController animated:YES]; 

然后调试器警告:当旋转多个视图控制器或视图控制器而不是窗口委托时,不支持使用两级旋转动画

但是,如果mod al查看不是tabController这个警告不会出现。

当我在导航控制器中弹出tabController模式视图时,这种行为会对应用程序造成什么危害?

或者我应该找到另一种方法来做到这一点?

我发现本网站上几个类似的问题,但我不明白这一点...

+0

http://stackoverflow.com/questions/576764/tab-bar-controller-inside-a-navigation-controller-or-sharing-a-navigation-root - 这是另一种方式来做到这一点。不要使用控制器,而应该创建自己的UIControllerView并将UITabBar附加到它。链接提供了源代码(位于GIT上)。 – TamusJRoyce

回答

14

的原因是,你正在使用它的预期用途之外的的UITabBarController。它只能用作根控制器,并且你需要类似于tabbar使用工具栏的东西。大约半年前,我遇到了一个确切问题。不幸的是,如果你这样使用它,你也会遇到其他问题。

UITabBarController documentation

由于类的UITabBarController从UIViewController的 类 继承,标签栏控制器有各自 自己的观点,即通过 视图属性进行访问。在部署 标签栏界面时,您必须将此视图安装为您窗口的根。 与其他视图控制器不同,选项卡 bar界面不应该是 作为另一个视图的子控件安装。

+0

真棒答案!解决了我的问题。 –

+0

这就是说,自iOS 2开始,我在'UINavigationController'内使用了'UITabBarController',并且从来没有遇到过这个问题。 – Pascal

+3

执行登录屏幕和登录到UITabBarController后的正确方法是什么?除了在ios7上的控制台消息,我没有看到在UINavigationController中使用控制器的任何其他问题 –

2

我有一个应用程序,其中UITabBarController是根视图控制器。根据应用程序内购买,子视图控制器是不同的。

在我的NIB中,我没有任何子视图控制器的UITabBarController。我添加的子视图控制器在application:didFinishLaunchingWithOptions:

这引起了警告“两阶段”旋转出现。只要我将一个单独的子视图控制器添加到NIB中的TabBar控制器,它就消失了。

12

这也将发生,如果你只添加一个空白的UITabBarController没有任何孩子的控制器,就像这样:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    //Tab bar controller 
    UITabBarController* tabBarController = [[UITabBarController alloc] init];  
    [[self window] setRootViewController:tabBarController]; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 

,如果你宣布它的RootViewController的前添加一个子视图控制器到的UITabBarController警告将消失你的UIWindow。方法在我自己的类:

+0

这个原因隐藏得很好。发现得好!我固定这样的: '的UIViewController * tempViewController = [[UIViewController中的alloc] INIT];'' UINavigationController的* tempNavController = [[UINavigationController的页头] initWithRootViewController:tempViewController];'' = self.tabBarViewController.viewControllers @ [tempNavController]; ' 我不再收到警告!但它有点凌乱。 – Sam

+0

+1“如果在将声明为UIWindow的rootViewController之前向UITabBarController添加子视图控制器,警告将消失。” – SolidSun

12

我子类的UITabBarController却忘记调用基类的viewWillAppear中时,得到了同样的警告。

- (void) viewWillAppear:(BOOL)animated { 

    [super viewWillAppear:animated] // <--- adding this fixed the warning 

    ... 

} 
+2

+1谢谢 - 我从来没有想到,造成这种警告 – anneblue

+0

谢谢。如此简单,如此容易忽视。正如安布鲁所说,如果我自己想出来,我会花费很长时间。 – Pega88

0

@Maciej Swic的回答对我有点帮助。

在我的情况下,我已经有2个孩子的UITabBarController。

出于某种奇怪的原因,我需要的是把

[self.window makeKeyAndVisible]

我添加了2个孩子后。

0

奥利弗的答案为我做了诀窍......虽然有趣,但我一直没有遇到任何问题,直到我添加了viewWillAppear:动画方法到子类tabviewcontroller ...在那一刻,一切失控了,直到它被固定通过添加[超级viewWillAppear中:动画]声明奥利弗建议...

0

只好问题与下面的顺序两段动画警告:

self.window.rootViewController = self.tabBarController; 
self.tabBarController.selectedIndex = 0; 

但更改订单帮助我消除警告。

self.tabBarController.selectedIndex = 0; 
self.window.rootViewController = self.tabBarController; 

希望这会有所帮助。