0

I'm implementing UITabBar in my app. I managed making it work by implementing UITabBarDelegate in my header file and using

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item

in my .m file (as explained in this tutorial).

Now, there are 3 scenarios in my app where I wish to set the selected UITabBarItem manually from within the code (and not based on user action):

  • Upon viewDidLoad
  • After didReceiveMemoryWarning
  • In a certain case when the user is entering another view controller - when they get back, they should get back to a different tab than the one they clicked on.

Can anyone direct me to how this should be done?

Mat
  • 202,337
  • 40
  • 393
  • 406
Ohad Regev
  • 5,641
  • 12
  • 60
  • 84

1 Answers1

1

The UITabBarController class has two properties for managing the selected tab, namely, selectedViewController and selectedIndex. Look into those in the reference.

albertamg
  • 28,492
  • 6
  • 64
  • 71
  • thanks for the reference, I did find my answer there - it was selectedItem property. – Ohad Regev Jul 24 '11 at 13:32
  • 1
    but what it the implemented controller is not a `UITabBarController`, what if i wanna use `UITabBar` and implement it delegate? and i wanna open the selected item view? – Scar Feb 21 '12 at 11:18