如何在swift中嵌入带有拆分视图控制器的标签栏控制器?

时间:2016-05-04 11:21:38

标签: ios xcode swift swift2

我猜测应用代理需要进行更改吗?谢谢你的帮助!

1 个答案:

答案 0 :(得分:14)

1)通过xcode创建样本Master / Detail

2)在故事板上拖动TabBarController

3)将TabBarController更改为初始视图控制器。

4)控制从TabBarController拖动到SplitViewController

5)为故事板中的SplitViewController分配标题

6)在app delegate中,将SplitViewController的引用替换为如下。

let tabBarViewController = self.window!.rootViewController as! UITabBarController
print(tabBarViewController.viewControllers?.count)
var splitViewController:UISplitViewController? = nil
for viewController in tabBarViewController.viewControllers! {
if viewController.title == "Master" {
    splitViewController = viewController as? UISplitViewController
}
}

let navigationController = splitViewController!.viewControllers[splitViewController!.viewControllers.count-1] as! UINavigationController
navigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController!.displayModeButtonItem()
splitViewController!.delegate = self