开发者

Objective C: How to switch from one Tab bar to another via program

开发者 https://www.devze.com 2023-03-13 19:42 出处:网络
I have 5 different tabs in my tabbar controller. My intention is to be able to switch from one tab bar via code. For example I am currently in the 5th tab of the app and when I click on the \'done\'

I have 5 different tabs in my tabbar controller.

My intention is to be able to switch from one tab bar via code. For example I am currently in the 5th tab of the app and when I click on the 'done' button, the app should开发者_如何学Python switch my view to the rootview controller belonging to the 1st tab.

Any advise on how I can do this?


Set selectedViewController property of UITabBarController:

self.myTabBarController.selectedViewController = myViewController;

Use as below

self.myTabBarController.selectedViewController 
    = [self.myTabBarController.viewControllers objectAtIndex:0];


Heres a simpler answer (if you know the index of the Tab Bar item is not in the "more" view controllers): just get a reference of the tabController and set the "selectedIndex" property

self.tabBarController.selectedIndex = 0;

Reference: https://developer.apple.com/library/ios/documentation/uikit/reference/UITabBarController_Class/Reference/Reference.html#jumpTo_6

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号