Is UITabBarItem overwritten by UIViewController?

I have a UITabBarController configured with two separate UIViewControllers. In init for the second UIViewController, I set UITabBarItem so that it displays the tab correctly:

UITabBarItem *tabBar = [self tabBarItem]; [tabBar setTitle:@"DATA"]; [tabBar setImage:[UIImage imageNamed:@"DATA.png"]]; 

This works great, the tab displays the name "DATA" and displays the correct icon image. In the same controller inside loadView, I set the UIViewController header:

 [self setTitle:@"Data Table"]; 

My question is that when I launch the application, my second tab reads “DATA”, however, when I click on the tab and loadView is called (I have a UITableView there), and I set the UNViewControllers header property to “Data table” Second tab also changes to "Data Table". Is there any way to fix / avoid this?

+4
source share
2 answers

Are you sure you want only two UIViewControllers, not UINavigationControllers? Usually you create a UIViewController, then create a UINavigationController with this view controller, and then put these navigation controllers in the UITabBarController.

This way your UIViewController will have a “name” that you can change.

+3
source
 self.navigationController.navigationBar.topItem.title = @"title"; 
0
source

Source: https://habr.com/ru/post/1336145/


All Articles