varun varun - 3 months ago 16
Objective-C Question

Double UINavigationBar in UITabBarController

We have a

UINavigationViewController
as root
viewController
in
AppDelegate
:

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


We are pushing a new
viewController
(
TabViewController
) from above Restore:

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


In this
TabViewController
we are adding
UITabBarController
programatically as subview and in this
UITabBarController
we have 5
UINavigationBarController
as view controllers:

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];


When we are rotating any view from these 5
UINavigationViewController
we are getting 2
UINavigationBar
on top in both
landscape
and
portrait
mode.

Check below image.

enter image description here

enter image description here

and didRotateFromInterfaceOrientation is not calling from these 5 UINavigationViewController view.

Any help?

Answer

When you add a view controller to another one as a subview manually you have to do the following:

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

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

This will propagate all the events to the child view controller and possibly remove unexpected behaviour.