gpt4 book ai didi

ios - 运行此代码时如何以及为何会出现信号 SIGABRT?

转载 作者:行者123 更新时间:2023-11-29 05:29:04 31 4
gpt4 key购买 nike

当我运行我的应用程序时, View Controller 中会调用一个函数,当发生这种情况时,我会收到信号 SIGABRT

如何解决这个问题?

功能:

func setRootViewController()
{
if Auth.auth().currentUser != nil
{
let tabVC = storyboard?.instantiateViewController(withIdentifier: "TabVC") as! TestViewController
view.window?.rootViewController = tabVC
view.window?.makeKeyAndVisible()
}
else
{
let welcomeVC = storyboard?.instantiateViewController(withIdentifier: Constants.Storyboard.welcomeVC) as! ViewController
view.window?.rootViewController = welcomeVC
view.window?.makeKeyAndVisible()
}
}

当它崩溃时,我会在控制台区域看到这个:

21 CoreFoundation 0x00007fff23ac4241 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 22 CoreFoundation 0x00007fff23ac416c __CFRunLoopDoSource0 + 76 23 CoreFoundation 0x00007fff23ac3944 __CFRunLoopDoSources0 + 180 24 CoreFoundation
0x00007fff23abe64f __CFRunLoopRun + 1263 25 CoreFoundation
0x00007fff23abde36 CFRunLoopRunSpecific + 438 26 GraphicsServices
0x00007fff37f64bb0 GSEventRunModal + 65 27 UIKitCore
0x00007fff46d562a3 UIApplicationMain + 1621 28 Do It !
0x000000010f1b654b main + 75 29 libdyld.dylib
0x00007fff51175cf5 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

最佳答案

尽量避免强行解开。试试这个:

func setRootViewController() {
if Auth.auth().currentUser != nil {
if let tabVC = storyboard?.instantiateViewController(withIdentifier: "TabVC") as? TestViewController {
view.window?.rootViewController = tabVC
view.window?.makeKeyAndVisible()
} else {
print("TabVC doesn't exist or is not a TestViewController")
}
} else {
let welcomeVC = storyboard?.instantiateViewController(withIdentifier: Constants.Storyboard.welcomeVC)
// you don't need to cast welcomeVC to a ViewController.
view.window?.rootViewController = welcomeVC
view.window?.makeKeyAndVisible()
}
}

如果这有帮助或者您有任何后续问题,请告诉我。

关于ios - 运行此代码时如何以及为何会出现信号 SIGABRT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57843408/

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