问题
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?
回答1:
The UITabBarController
class has two properties for managing the selected tab, namely, selectedViewController
and selectedIndex
. Look into those in the reference.
来源:https://stackoverflow.com/questions/6806770/how-to-set-the-selected-item-in-a-uitabbar-from-within-the-code