尝试让应用程序启动时显示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
}
答案 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
}