Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITabBarController selected item

I have UITabBarController and push on two views. I want the first view to be the default and the button to be in the "selected" state when it loads.

My problem is the tabBarItem does not have the selected background when it loads. I have to tap on it to show the selected. I'm also using custom images for the tab bar items as well and have them being configured in each view that gets added to the tabBarController.

I'm using this to set the selected item:

_tabBarController.selectedViewController = [_tabBarController.viewControllers objectAtIndex:0];

The UITabBarItem gets created in each view that I add to the tabBarController:

-(UITabBarItem *)tabBarItem
{
    return [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"tab_select_indicator_map.png"]  tag:0];
}

How can I also have the tabBarItem show the selected state?

like image 212
Steve Sloka Avatar asked Apr 17 '26 21:04

Steve Sloka


1 Answers

Use following code of display selected tabBarItem when your tabBar is loaded.

[_tabBarController setSelectedIndex:0]; // your can set index as per your requirement.

Eited:

Make sure that you created your tabBarItem such like

UITabBarItem* myTestingItem = [[UITabBarItem alloc] init];
[myTestingItem  setFinishedSelectedImage: [UIImage imageNamed: @"btnTabItem-SelectedImage.png"]
              withFinishedUnselectedImage: [UIImage imageNamed: @"btnTabItem.png"]];
like image 159
iPatel Avatar answered Apr 20 '26 12:04

iPatel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!