我正在尝试从AppDelegate.swift
的初始视图控制器上弹出我的登录页面,并且正在使用
let authVC = storybaord.instantiateViewController(withIdentifier: "StartVC")
实例化它。但是,视图控制器链接到导航控制器,当我使用代码时,当我单击视图控制器的按钮时,它会使应用程序崩溃。代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
if Auth.auth().currentUser == nil {
let storybaord = UIStoryboard(name: "Main", bundle: Bundle.main)
let authVC = storybaord.instantiateViewController(withIdentifier: "StartVC")
window?.makeKeyAndVisible()
window?.rootViewController?.present(authVC, animated: false, completion: nil)
}
return true
}
在Main.Storyboard
文件中,我在Navigation Controller的第一个视图控制器上具有情节提要ID ("StartVC")
。屏幕截图:http://prntscr.com/lp8fez |
http://prntscr.com/lp8flq
此处显示崩溃日志:
Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'toName'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.
答案 0 :(得分:1)
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
if Auth.auth().currentUser == nil {
let storybaord = UIStoryboard(name: "Main", bundle: Bundle.main)
let authVC = storybaord.instantiateViewController(withIdentifier: "StartVC")
window?.rootViewController?= authVC
window?.makeKeyAndVisible()
}
return true
}
我已经使用了此代码,并且对我有用。尝试让我知道是否需要更多帮助。