Change ViewController for a TabBarItem

删除回忆录丶 提交于 2019-12-11 03:35:26

问题


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:


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.



来源:https://stackoverflow.com/questions/5303787/change-viewcontroller-for-a-tabbaritem

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