当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - iOS 10 UITabbar selecting other tab shows it's title in index 0

问题描述:

I show 5 tabs using UITabbar. How ever the first tab title keeps changing when i press a button. For example let the tabbar name be "first", alpha, beta, gamma.

I select the "first" tabbar and click a button in the screen which keep changing title names to "second", "third", and so on.

My problem is when the app starts the title text shows 2 same names. One is selected color blue and other is deselected color gray. When I select the tabs alpha, beta, gamma those titles also applies in "first". So the text are clustered in first tabbar. This works fine in iOS 9. From iOS 10 I get this title problem. The tabbar image are working fine its not duplicated.

FirstViewCtrl* tripVc = [ FirstViewCtrl new ];

UINavigationController* firstNavCtrl = [ [ UINavigationController alloc ] initWithRootViewController:firstVc ];

UITabBarController* tabBarController = [ UITabBarController new ];

[ tabBarController.tabBar setBarStyle:UIBarStyleBlack ];

tabBarController.viewControllers = @[firstNavCtrl, alphaNavCtrl, betaNavCtrl, gammaNavCtrl];

tripVc.tabBarItem = [ [ UITabBarItem alloc ] initWithTitle:@"First" image:[ UIImage imageNamed:@"firstIcon"] selectedImage:[UIImage imageNamed:@"firstIcon_mo"] ];

[ self.view addSubview:tabBarController.view ];

I fixed this by different method. I am not sure this is correct or why its happening. Instead of setting

[ self setTitle:@"First" ];

I set it as

[ self.navigationItem setTitle:@"First" ];

[ self.tabBarItem setTitle:@"First" ];

By this way if i want to change title the text are not overlapped.

Anyone with any idea why is this happening from iOS 10

网友答案:

You need to set title of for all ViewController. such as below

FirstViewCtrl* tripVc = [ FirstViewCtrl new ];
tripVC.title = @"First";

alphaNavCtrl* tripVc = [ alphaNavCtrl new ];
alphaNavCtrl.title = @"alpha";
分享给朋友:
您可能感兴趣的文章:
随机阅读: