UITabBarController 中的双 UINavigationBar

Double UINavigationBar in UITabBarController

我们有一个 UINavigationViewController 作为根 viewControllerAppDelegate:

 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 视图调用。

有什么帮助吗?

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

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

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

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