以编程方式更改UITabBar选定视图

时间:2015-06-04 08:35:08

标签: ios objective-c cocoa-touch

我正在尝试以编程方式更新我的UITabBar所选视图我尝试过以下代码:

UIViewController *currentView = self.frostedViewController.contentViewController;
NSLog(@"Current Index %lu", currentView.tabBarController.selectedIndex);
currentView.tabBarController.selectedIndex = 3;
NSLog(@"changing index %lu", currentView.tabBarController.selectedIndex);

//self.frostedViewController.contentViewController = categorie;
[self.frostedViewController hideMenuViewController];

但标签栏视图未更改检查此图片: enter image description here

1 个答案:

答案 0 :(得分:0)

通过设置selectedViewController:

func selectTab(atIndex index: Int) {
    if index >= 0 && index < tabBarController.viewControllers.count {
       tabBarController.selectedViewController = tabBarController.viewControllers[index]
    }
}