How to insert a UINavigationController inside a UITabBarController

How to insert a UINavigationController inside a UITabBarController .

I currently have a main UITabBarController with a declaration inside the application delegate (so the main tab)

 self.window.rootViewController = self.tabBarController; 

And inside one of the tabs I want to insert a UINavigationController and cannot get it.

The code is constructed as follows:

  • MainWindow.xib with a UITabBarController object with a tab entered as UINavigationController (specify NavigationHistory.xib ) - screenshot: invalid link
  • NavigationHistory.xib contains only the UINavigationController where the viewpoint points to History.xib
  • History.xib have only a UITableView element - screenshot: invalid link

And now the UIViewController does not display my view1, and I don’t know why it could be. Maybe you have some kind of clue? or tell me the place where such a configuration is made.

+4
source share
5 answers

Write the code in the appdelegate.m file .....

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; NSMutableArray *Mutablearray = [[NSMutableArray alloc] init]; UIViewController *1st_View = [[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil]; UINavigationController *Navigation = [[UINavigationController alloc] initWithRootViewController:1st_View]; [Mutablarray addObject:Navigation]; UIViewController *2nd_View = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil]; UINavigationController *Navigation = [[UINavigationController alloc] initWithRootViewController:2nd_View]; [Mutablearray addObject:Navigation]; self.tabBarController = [[UITabBarController alloc] init]; self.tabBarController.viewControllers = Mutablearray; self.window.rootViewController = self.tabBarController; [self.window makeKeyAndVisible]; return YES; } 
0
source

Add your controller object to the UINavigationController and add this navigation controller object to the UITabBarController

0
source

UINavigationController is a subclass of UIViewController, UITabBarController expects an array of UIViewControllers (and therefore UINavigationController); this tells me that I can give the UITabBarController an array of UINavigationControllers (or its footers) giving the desired interaction.

Link: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITabBarController_Class/

0
source
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; UITabBarController *tab = [[UITabBarController alloc] init]; SimpleTableViewController *tableView = [[SimpleTableViewController alloc] init]; UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:tableView]; UITabBarItem *item = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemHistory tag:0]; nav1.tabBarItem = item; AboutViewController *about = [[AboutViewController alloc] init]; UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:about]; UITabBarItem *item2 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:0]; nav2.tabBarItem = item2; tab.viewControllers = @[nav1,nav2]; self.window.rootViewController = tab; [self.window makeKeyAndVisible]; return YES; 

}

0
source

All Articles