Icons disappear on the Advanced tab

In my iPad application, I use tabBarController. I run the following code to select a specific tab:

[tabBarController setSelectedViewController:myNavigationController]; 

(I am changing the selectedViewController property of the UITabBarController class, see apple docs )

This works fine; the only problem is that when users go to the "More ..." screen using the upper left button, the icon for the previously selected tab is missing:

an icon is missing

When I move manually, there is no problem. Icons are always visible on the Advanced screen. The problem only occurs when I use the setSelectedViewController method.

Tab bar items are created as follows:

 newVC = [[SynchronizeViewController alloc] init]; newVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"SYNCHRONIZE", @"synchronize tab label") image:[UIImage imageNamed:@"02-redo.png"] tag:0]; 

Has anyone encountered the same problem and found a way to fix this? Thanks in advance!

+4
source share
3 answers

Could you add the following method for controller synchronization:

 - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate; UITableView *view = (UITableView *)appDelegate.tabBarController.moreNavigationController.topViewController.view; [view reloadData]; } 
+2
source

The problem is that you are creating UITabBarItem yourself. From the docs -tabBarItem :

When you first access the resource, a UITabBarItem is created.

Therefore, you do not need to create it, just do the following:

 newVC.tabBarItem.title = @"Your Title"; // Default is view controller title. newVC.tabBarItem.image = yourImage; 

Attempted explanation: for some reason, the UITabBarController decided to internally recreate all the elements of the tab bar or something else. And your copy was lost, and the default name was used. Or maybe only the image was lost, who knows. This is called undefined behavior.

+1
source

Try deleting the file from the project. Get a clean assembly and add it back to the project with a different name.

0
source

All Articles