How to Set the Selected Item in a UITabBar From within the Code?

六眼飞鱼酱① 提交于 2019-12-11 23:34:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!