【发布时间】:2017-07-06 12:42:12
【问题描述】:
我有一个UITabbarController,其中 5 个 ViewControllers 作为索引号 0、1、2、3、4,现在,如果它在 iPhone 中运行,然后加载 5 个视图控制器,那很好,但如果我将 iPhone 更改为iPad,索引号 4 应该是不同的ViewControllers。
例如
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)
我们将不胜感激。
【问题讨论】:
-
你的设置vc是不是也嵌入到tabbar中了?
-
@PankajGupta 不,ViewController 5 已嵌入,但我需要将其替换为该索引的另一个未嵌入的视图控制器。
-
@AbhishekMitra 检查我的答案
标签: ios iphone swift3 uitabbarcontroller