我正在创建一个包含快速入门屏幕的应用程序。在AppDelegate.swift中,我将navigationController设置为根视图控制器。但我有一个入门屏幕,需要将其添加到代码中。每当我运行应用程序时,我都会Thread 1: SIGNAL SIBAGRT
。这是我的代码:
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [ .
UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
let sb = UIStoryboard(name: "Onboarding", bundle: nil)
let initialViewController = sb.instantiateInitialViewController()
window?.rootViewController = initialViewController
window?.makeKeyAndVisible()
let navigationController = window!.rootViewController as! UINavigationController
let controller = navigationController.viewControllers[0] as! AllListsViewController
controller.dataModel = dataModel
答案 0 :(得分:0)
试试:
window = UIWindow(frame: UIScreen.main.bounds)
let storyboard = UIStoryboard(named:"Onboarding",bundle: nil)
let nvc = storyboard.instantiateInitialViewController() as? UINavigationController // since your storyboard start with a navigationController
let topVc = nvc.topViewController as? AllListsViewController // then we get the first controller associated to that navigationController
topVc?.dataModel = dataModel
window?.rootViewController = nvc // still set your navigationController as the root of your application
window?.makeKeyAndVisible()