使用UISplitViewController的多个DetailViewControllers

时间:2015-10-14 16:02:59

标签: ios swift uisplitviewcontroller master-detail

目前,我有一个带有MasterViewController和DetailViewController的SplitViewController。我想知道是否有更多DetailViewControllers的方法。现在我在tableView左侧有一个项目列表,如果你点击它们,它们会转到全屏视图。如何点击时,我如何让它显示在splitview右侧的面板内?因此,参考此图像 - 如何让我的视图在细节部分中显示为黄色?现在,当我点击相当于"黄色" - 黄色显示为全屏,而不是细节。 http://2uagoo1zzsoo4bcz3347bs2y.wpengine.netdna-cdn.com/wp-content/uploads/2012/08/Image003.png

额外信息:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    if indexPath.row == 0 {

        let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

        let vc: UINavigationController = storyboard.instantiateViewControllerWithIdentifier("newViewController") as! UINavigationController

        self.presentViewController (vc, animated: true, completion: nil)

    } else if indexPath.row == 3 {

        let storyboardTwo: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

        let vcTwo: UINavigationController = storyboardTwo.instantiateViewControllerWithIdentifier("newViewController4") as! UINavigationController

        self.presentViewController(vcTwo, animated: true, completion: nil)
    }

1 个答案:

答案 0 :(得分:0)

我相信你需要使用show showDetailViewController方法:

将指定的视图控制器显示为拆分视图界面的辅助视图控制器。

func showDetailViewController(_ vc: UIViewController,
                   sender sender: AnyObject?)

所以在你的情况下,它将更像这样使用。在didSelectRowAtIndexPath函数中:

{
    let vc:UIViewController
    if indexPath.row == 0 {
        let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        vc: UINavigationController = storyboard.instantiateViewControllerWithIdentifier("newViewController") as! UINavigationController   



    } else if indexPath.row == 3 {
        let storyboardTwo: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
       vc: UINavigationController = storyboardTwo.instantiateViewControllerWithIdentifier("newViewController4") as! UINavigationController

    }else {
     // handle this case
        vc = ...
    }
    // Grab the Split View Controller 
    let splitVC = // get Split View Controller
    splitVC.showDetailViewController(vc,sender:nil)
}