I'm developing an app for iOS5 and up and I don't use storyboards or IB. I'm creating a custom UITabBarController
and in my AppDelegate
I'm putting in it 4 view controllers with only 1 UINavigationController
(can't tell why).
It results in a behaviour where I can push new VC only from the first tab, which is apparently, packed into a UINavigationController
called navController
:
SGTabBarController *tabBarController = [[SGTabBarController alloc] init];
SGHomeViewController* vc1 = [[SGHomeViewController alloc] init];
SGChooseOSAgainViewController* vc3 = [[SGChooseOSAgainViewController alloc] init];
SGSmsServicesViewController* vc4 = [[SGSmsServicesViewController alloc] init];
SGSupportViewController *vc5 = [[SGSupportViewController alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:vc1];
NSArray* controllers = [NSArray arrayWithObjects:navController, vc3, vc4, vc5, nil];
tabBarController.viewControllers = controllers;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = tabBarController;
[navController setNavigationBarHidden:YES animated:NO];
[self.window makeKeyAndVisible];
Why is that? Should I create a separate UINavigationController
for each tab? I took this code from Apple's documentation.
Suppose you have a tabbarController. Now you can add any viewController or any NavController in your tabController. NavController can contain viewController. But you might have confusion where you will use navController or viewController. You will use viewController where you don't need navigation, I mean where you don't need.
Here is an code example where the first view contains only view and the second view contains navigation controller. You can't push new view in first view, but you can easily push new view in second view.
Call this method from didFinishLaunchingWithOptions in AppDelegate. here HomeView and FloorPlanView is two different views, you need to add these views and class file first.
If you want to navigate in each tab, YES you should add each viewController embedded in a navigationController.
Refer to my answer here:
UITabBarController Issue
Yes, you can. Try something like this code in yourUITabBarController.m:
and this in you AppDelegate.m: