![](/img/trans.png)
[英]Swift Project Terminating with uncaught exception of type NSException
[英]AppDelegate didFinishLaunchingWithOptions launchOptions - terminating with uncaught exception of type NSException Swift 3.0
我正在嘗試使用Swift 3.0創建登錄/受保護的頁面會話頁面
因此,我在AppDelegate.swift中創建了didFinishLaunchingWithOptions launchOptions函數,如下所示
AppDelegate.swift
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let rootViewController = self.window!.rootViewController
let mainStoryBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let isUserLoggedIn:Bool = UserDefaults.standard.bool(forKey: "isUserLoggedIn")
if(!isUserLoggedIn){
let loginViewController = mainStoryBoard.instantiateViewController(withIdentifier: "loginview") as! LoginVC
window!.rootViewController = loginViewController
window!.makeKeyAndVisible()
}
else{
let protectedPage = mainStoryBoard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
window!.rootViewController = protectedPage
window!.makeKeyAndVisible()
}
return true
}
}
它構建成功,但是運行應用程序時出現錯誤。 錯誤如下
由於未捕獲的異常“ NSInvalidArgumentException”而終止應用程序,原因:“ Storyboard()不包含標識符為“ loginview”的視圖控制器
libc ++ abi.dylib:以類型為NSException(lldb)的未捕獲異常終止
在情節提要中選擇LoginVC,然后在檢查器窗口中的情節提要ID中提供loginview
標識符
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.