如何获取UISplitViewController的MasterVC以显示何时启动应用程序

时间:2017-06-22 02:26:40

标签: ios swift3 uisplitviewcontroller

尝试让应用程序启动时显示MasterVC。现在,DetailVC显示应用程序何时启动。这是我的splitViewController代码。我确定解决方案是在Delegate方法中。

我使用的是CoreData,模型是var items = [Notes]()

理想的结果是,当应用程序启动时,MasterVC tableView正在显示,并通过点击tableCell navigationController推送到DetailVC以显示{{1}数据。该应用程序已经这样做了。启动时只需要加载MasterVC。谢谢。

indexPath

UISplitViewController委托

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    let splitViewController = self.window!.rootViewController as! UISplitViewController
    let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as! UINavigationController
    navigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem
    splitViewController.delegate = self as? UISplitViewControllerDelegate
    return true
}

1 个答案:

答案 0 :(得分:0)

您需要实现splitViewController(_:collapseSecondary:onto:)协议的UISplitViewControllerDelegate方法并返回true

  

返回值

     

false,以使拆分视图控制器尝试合并   辅助视图控制器的内容放到折叠的界面中,或   true表示您不希望拆分视图控制器执行此操作   使用辅助视图控制器进行任何操作。

新的Master-Detail App项目中随附的示例代码:

func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool {
    guard let secondaryAsNavController = secondaryViewController as? UINavigationController else { return false }
    guard let topAsDetailController = secondaryAsNavController.topViewController as? DetailViewController else { return false }
    if topAsDetailController.detailItem == nil {
        // Return true to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded.
        return true
    }
    return false
}