Ios 尝试更改根视图控制器时,应用程序委派因NSException而崩溃
尝试在第一次运行应用程序后更改根视图控制器,但它崩溃Ios 尝试更改根视图控制器时,应用程序委派因NSException而崩溃,ios,swift,appdelegate,Ios,Swift,Appdelegate,尝试在第一次运行应用程序后更改根视图控制器,但它崩溃 import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplic
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if(UserDefaults.standard.bool(forKey: "notFirstInApp") == false){
UserDefaults.standard.set(true, forKey: "notFirstInApp")
let state = StateTableViewController()
window?.rootViewController = state
}else{
let home = HomeViewController()
window?.rootViewController = home
}
return true
}
撞车
libc++abi.dylib:以NSException(lldb)类型的未捕获异常终止
提前感谢。您不能通过viewController名称直接设置rootViewController。请检查下面的代码
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "LoginSignupVC")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
这不是初始化ViewController的正确方法。详情请参阅此答案