Change ViewController for a TabBarItem

2019-07-08 09:01发布

Is it possible to change/replace ViewContoller (and View) for one of the Tabs in a UITabBarController?

I would like to switch between 3 different ViewControllers in any order from a specific Tab (that´s why NavigationController is not possible).

1条回答
对你真心纯属浪费
2楼-- · 2019-07-08 09:30

They are set (in mass) using setViewControllers:animated: so you could do something like this.

// Assume tabController is the tab controller 
// and newVC is the controller you want to be the new view controller at index 0
NSMutableArray *newControllers = [NSMutableArray arrayWithArray:tabController.viewControllers];
[newControllers replaceObjectAtIndex:0 withObject:newVC];
[tabController setViewControllers:newControllers animated:YES];

Hope that helps.

查看更多
登录 后发表回答