转到 DetailViewController (SplitViewController)

Segue to DetailViewController (SplitViewController)

我很难选择在拆分视图控制器中显示为详细视图的视图控制器。 showDetail 后面的视图控制器似乎有一些默认调用者,但我找不到位置。当加载拆分视图控制器时,它显示 DetailViewController 作为我尝试将其设置为 OverviewViewController 拆分的详细信息。 showDetail segue 不会在加载时调用,但它仍然是默认设置。

当我在 master 上覆盖 didSelectRowAtIndexPath 时,我看到闪烁,因为它在设置 OverviewViewController 之前短暂地设置了 DetailViewController

这是我的代码:

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    self.navigationItem.leftBarButtonItem = self.editButtonItem()
    if let split = self.splitViewController {
        let controllers = split.viewControllers
        self.detailViewController = (controllers[controllers.count-1] as! UINavigationController).topViewController as? OverviewViewController

    }
}

// MARK: - Segues
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    print("did select row")
    NSOperationQueue.mainQueue().addOperationWithBlock {
        self.performSegueWithIdentifier("showOverview", sender: self)
    }

}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "showDetail" {
        print("segue to showDetail")
            let controller = (segue.destinationViewController as! UINavigationController).topViewController as! DetailViewController
            controller.injectOrder(gobl_meal_orders[indexPath.row])
            controller.detailItem = object
            controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem()
            controller.navigationItem.leftItemsSupplementBackButton = true
        }
    }else if segue.identifier == "showOverview"{
        print("show overview called")
    }
}

这个隐藏的视图控制器预选在哪里?

如果我没理解错的话,您不希望在加载 splitview 控制器时显示详细视图。

控制它的方法是为您的 UISplitViewController 使用自定义 class 并实现以下委托方法

splitViewController(_:collapseSecondaryViewController:ontoPrimaryViewController:)

这是一个例子。

import UIKit

class MyCircleUISplitViewController: UISplitViewController, UISplitViewControllerDelegate {

  override func viewDidLoad() {
    super.viewDidLoad()
    delegate = self

    // Do any additional setup after loading the view.
  }

  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
  }

  func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController: UIViewController, ontoPrimaryViewController primaryViewController: UIViewController) -> Bool {
    return true
  }      
}

这里还有一个不错的 blog UISplitViewControllers,您可能会觉得有趣。