Swift 3如何以模态方式呈现splitview控制器?

时间:2017-06-30 13:53:00

标签: swift3 uiviewcontroller segue xcode8 uisplitview

您好我正在尝试从UiViewController呈现UiSplitViewController。我正在UiViewController中进行一些搜索,并根据结果显示UiSplitViewController。我怎么能以编程方式做到这一点?到目前为止,我在google搜索后尝试了3种方法

1。self.performSegue(withIdentifier: "SearchComplete", sender: self)

2。self.present(PrimarySplitViewController(), animated: true, completion: nil)

3。let detailViewController = self.storyboard?.instantiateViewController(withIdentifier: "SplitView") as! UISplitViewController self.splitViewController?.viewControllers[1] = detailViewController

上述方法都没有奏效,我该如何解决这个问题。谢谢。

1 个答案:

答案 0 :(得分:1)

让mainStoryboard:UIStoryboard = UIStoryboard(名称:" Main",bundle:nil)

    let viewController = mainStoryboard.instantiateViewController(withIdentifier: "SplitView") as! UISplitViewController

    UIApplication.shared.keyWindow?.rootViewController = viewController 

您必须设置根视图控制器