我有一个 UITabbarController
与5 ViewControllers
作为索引号0,1,2,3,4,现在,如果它在iPhone上运行然后加载了5个viewcontrollers,那很好,但是如果我将iPhone改为iPad,索引号4应该是不同 ViewControllers
.
Ex.
if iPad{
tabbarcontroller's index 4 should be B Viewcontroller
}else{
tabbarcontroller's index 4 should be A Viewcontroller
}
我在目标c,link here得到了答案,但我无法为Swift做出答案,这是我的代码:
let settingVc = self.storyboard?.instantiateViewController(withIdentifier: "SettingTabbarController") as! SettingTabbarController
var controllers : NSMutableArray = [self.viewControllers!][0] as! NSMutableArray
print(controllers)
controllers.replaceObject(at: 4, with: settingVc)
self.setViewControllers(controllers, animated: true)
任何帮助将不胜感激 .
1 回答
在这里,您可以更改viewController以获取特定索引,如下所示
在你的
UITabbarController