【问题标题】:Double UINavigationBar in UITabBarControllerUITabBarController 中的双 UINavigationBar
【发布时间】:2017-01-13 14:48:35
【问题描述】:

我们在AppDelegate 中有一个UINavigationViewController 作为根viewController

 Restore *callRestore=[[Restore alloc]initWithNibName:@"Restore" bundle:nil];
 self.navigationController = [[UINavigationController alloc] initWithRootViewController:callRestore];
 self.window.rootViewController = self.navigationController;

我们正在从上方恢复一个新的viewController (TabViewController):

 callTabView=[[TabViewController alloc] initWithNibName:@"TabViewController" bundle:nil];
 [self.navigationController pushViewController:callTabView animated:YES];

在这个TabViewController 中,我们以编程方式添加UITabBarController 作为子视图,在这个UITabBarController 中,我们有5 个UINavigationBarController 作为视图控制器:

NSArray* controllers = [NSArray arrayWithObjects:navControllerDashboard, navControllerAccounts, navControllerTransation,navControllerCallDisplayReports,navControllerMore, nil];
self.tabBarController.viewControllers = controllers;
self.tabBarController.delegate = self;
self.tabBarController.view.frame = self.view.frame;
[self.view addSubview:self.tabBarController.view];

当我们从这 5 个UINavigationViewController 中旋转任何视图时,在landscapeportrait 模式下,我们都会在顶部获得2 个UINavigationBar

查看下图。

并且 didRotateFromInterfaceOrientation 并没有从这 5 个 UINavigationViewController 视图中调用。

有什么帮助吗?

【问题讨论】:

  • callTabView 是 UIViewController。我们正在初始化 tabBarController 并像这样添加 tabBarController: self.tabBarController = [[UITabBarController alloc] init]; [self.view addSubview:self.tabBarController.view];

标签: ios objective-c iphone uitabbarcontroller uinavigationbar


【解决方案1】:

当您手动将视图控制器作为子视图添加到另一个视图控制器时,您必须执行以下操作:

UIViewController *parent = ...;
UIViewController *child = ...;

[child willMoveToParentViewController: parent];
[parent addChildViewController: child];
[parent.view addSubview: child.view];
[child didMoveToParentViewController:parent];

这会将所有事件传播到子视图控制器并可能删除意外行为。

【讨论】:

    猜你喜欢
    • 2012-09-28
    • 1970-01-01
    • 2012-01-30
    • 2011-05-04
    • 1970-01-01
    • 2016-10-14
    • 2011-11-24
    • 1970-01-01
    • 2011-01-07
    相关资源
    最近更新 更多