Home > Software design >  Where should this tab bar controller be embedded?
Where should this tab bar controller be embedded?

Time:12-31

The Initial View Controller of this project is a Navigation Controller. I want to show a Tab Bar Controller on a View Controller later in the view hierarchy after the user signs in.

When I embed a Tab Bar Controller on the View Controller I want it to be on, the navigationBar I have programmatically implemented gets overridden with a new navigationBar item that, when pressed, leads the user back to the log in page.

Here is the code for the navigationBar.

self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

//Changes The Title Color
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName]];

//Sets The Navigation Controller Font
[self.navigationController.navigationBar setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], NSForegroundColorAttributeName,
[UIFont fontWithName:@"ArialMT" size:12.0], NSFontAttributeName,nil]];
[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x0080ff)];

self.navigationController.navigationBar.translucent = YES;

self.navigationItem.leftBarButtonItem = btnRefresh;

//
self.navigationItem.rightBarButtonItem = btnCompose;

Here is how the navigationBar is supposed to be implemented on the View Controller:

enter image description here

Here is what happens when a Tab Bar Controller in embedded in the View Controller that I want it to be on:

enter image description here

What is the correct way to show a Tab Bar Controller on this View Controller that will preserve the existing navigationBar? Apple's Documentation on Tab Bar Controllers seems extensive and it seems it should be implemented programmatically.

CodePudding user response:

According to Apple docs TabBarController should not be pushed to UINavigationController. Instead you can just use UITabBar and UITabBarDelegate to get same effect. You can refer below link of documentation.

https://developer.apple.com/documentation/uikit/uinavigationcontroller/1621887-pushviewcontroller

  • Related