user4951
user4951

Reputation: 33050

How to Use TabBarViewController with a NavigationController

I know I can do this

 [self.navigationController pushViewController:self.someUITabBarController animated:YES];

And that means putting UITabBarController on a navigationgController somehow

What about if I want someUITabBarController to be the first controller (the one located on the lowest level) of navigationController?

I simply cannot change the rootViewController of the NavigationController into someUITabBarController

Upvotes: 0

Views: 2234

Answers (2)

Sola
Sola

Reputation: 1522

Erm not sure this is what you want. Below this code will be put under the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions in you "appDelegate" class.

UITabBarController *tabController = [[UITabBarController alloc] init];
UIViewController *viewController1 = ...
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController1];

NSArray *controllers = [NSArray arrayWithObjects:navigationController, nil]; // can add more if you want

[tabController setViewControllers:controllers];

// this is for custom title and image in the tabBar item
navigationController.tabBarItem.title = @"abc";
[navigationController.tabBarItem setImage:[UIImage imageNamed:@"abc.png"]];

self.window.rootViewController = tabController; // or [self.window addSubview: tabController.view];
[self.window makeKeyAndVisible];

Upvotes: 2

EmptyStack
EmptyStack

Reputation: 51374

I am not sure if this works. But try this,

UINavigationController *navCont = [[UINavigationController alloc] init];
[navCont pushViewController:navCont animated:NO];

Upvotes: 1

Related Questions