MoreNavigationController images disappearing on select

允我心安 提交于 2019-12-06 12:39:34

The issue is because you're wrapping your InfoViewController in a UINavigationController.

When you click on the table row in MoreNavigationController, the controller uses the tabBarItem in UINavigationController while it does its transition. Because this is nil (in your code), the image in MoreNavigationController disappears. When the transition finally finishes, MoreNavigationController picks up the tabBarItem in InfoViewController

Try this:

InfoViewController* infoViewController = [[InfoViewController alloc] init];
infoViewController.tabBarItem.image = [UIImage imageNamed:@"90-life-buoy.png"];
infoViewController.tabBarItem.title = @"More Info";
infoViewController.title = @"More Info";
UINavigationController* infoNavController = [[UINavigationController alloc] initWithRootViewController:infoViewController];
//Set the tabBarItem for UINavigationController
infoNavController.tabBarItem = infoViewController.tabBarItem
[infoViewController release];

Here's a video reproducing and fixing the issue: Item 7 has an empty tabBarItem.image while Item 6 has tabBarItem.image set

I'm not sure, but have you tried setting the NavigationCotroller's .tabBarItem?

Not sure if I understand correctly, but on the top of my head here are some suggestions (The More Tab Bar item shouldn't disappear at all times, that is created automatically)

  1. Have you tried subclassing your UINavigationController that is being used for the MoreController's place and set its tab bar items properties there, therefore making sure you have control over its lifetime ?

  2. Subclass your UIViewController's that you wish to push onto the navigation stack and have them use the same tab bar item ?

  3. Mimic the default functionality, create your own UITableViewController to act as the More Controller, and at each tap of the rows, do what you want, also in a custom way.

PS: Try setting images name without the .png extension. This way you will automatically load the @2x resource as well. Eg: [UIImage imageNamed:@"90-life-buoy"]

Link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!