Reputation: 195
I'm having a trouble with a UITabBar with UITabBarItem added programmatically, the selected item is not being highlighted in white as usual.
Here's the source
UIImage *imageX = [UIImage imageNamed:@"sample.png"];
UITabBarItem *tabBarItem = [[UITabBarItem alloc]initWithTitle:@"Sample" image:imageX tag:1];
NSArray *array = [NSArray arrayWithObjects:tabBarItem, nil];
[tabBar setItems:array];
When I select the item, the method didSelectItem of the delegate is called and the action is executed, but the image is not being highlighted by the bar...
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
Anyone know what's wrong ? I have to call other method to pass the highlighted image or something like that ?
The items of the tab bar are added programmatically but the tab bar I add via Storyboard.
Also, I did a test where the tab bar and the tab bar items are added via Storyboard, and everything works, including the highlighted icon is shown when it's selected
Thanks !
Upvotes: 0
Views: 996
Reputation: 6697
I solve the problem by adding code in - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item;
function :
self.tabBar.selectedItem = item;
I don't know why I have to do this, but it's working.
Upvotes: 0