gpt4 book ai didi

ios - Swift - 在 AppDelegate 中实例化 View Controller

转载 作者:行者123 更新时间:2023-11-28 23:40:36 28 4
gpt4 key购买 nike

我试图让我的登录页面从 AppDelegate.swift 的初始 View Controller 上弹出,并且我正在使用
let authVC = Storybaord.instantiateViewController(withIdentifier: "StartVC")
来实例化它。但是, View Controller 链接到导航 Controller ,当我使用代码时,当我单击 View Controller 的按钮时,它会使应用程序崩溃。代码:

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 文件中,我在导航 Controller 的第一个 View Controller 上有 Storyboard ID ("StartVC")。屏幕截图:http://prntscr.com/lp8fez | http://prntscr.com/lp8flq

这是崩溃日志:
由于未捕获的异常“NSGenericException”而终止应用程序,原因:“无法找到用于 segue 'toName' 的导航 Controller 。仅当源 Controller 由 UINavigationController 实例管理时才能使用推送 Segue。

最佳答案

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
}

我已经使用了这段代码并且它对我有用。如果需要更多帮助,请尝试告诉我。

关于ios - Swift - 在 AppDelegate 中实例化 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53567653/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com