寻找DetailViewController(SplitViewController)

时间:2015-10-24 20:35:42

标签: ios swift xcode-storyboard

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

当我覆盖了主设备上的didSelectRowAtIndexPath时,我会看到一个闪烁,因为它会在设置DetailViewController之前短暂设置OverviewViewController

这是我的代码:

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")
    }
}

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

1 个答案:

答案 0 :(得分:1)

如果我理解正确,您不希望在加载splitview控制器时显示详细信息视图。

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

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
  }      
}

这也是UISplitViewControllers上的一个很好的blog,你可能会感兴趣。