Abh*_*tra 2 iphone uitabbarcontroller ios swift3
我有一个UITabbarController5ViewControllers作为索引号 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
}
Run Code Online (Sandbox Code Playgroud)
我在目标 c 中得到了答案,链接在这里,但我无法为 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)
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。
在这里,您可以更改特定索引的 viewController,如下所示
在你的 UITabbarController
self.viewControllers?.remove(at: 4)
let newItemController = UIStoryboard(name: "Settings", bundle: nil).instantiateViewController(withIdentifier: "SettingsViewController") as! SettingsViewController
newItemController.title = "Settings"
newItemController.tabBarItem.image = UIImage(named: "ic_tab_settings")
newItemController.tabBarItem.isEnabled = true
self.viewControllers?.insert(newItemController, at:4)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1130 次 |
| 最近记录: |