问题描述
我正在尝试使用Swift 3.0创建登录/受保护的页面会话页面
I'm trying to create login/protected page session page using Swift 3.0
因此,我在AppDelegate.swift中创建了如下的 didFinishLaunchingWithOptions launchOptions 函数
Therefore, I created didFinishLaunchingWithOptions launchOptions function in AppDelegate.swift as below
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
}
}
它构建成功,但是运行应用程序时出现错误.错误如下
It build successfully, But i got an error when apps run. The error as below
libc ++ abi.dylib:以类型未捕获的异常终止 NSException(lldb)
libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
推荐答案
很可能您没有设置LoginVC的Storyboard ID.在情节提要中选择LoginVC,并将情节提要ID设置为"loginview".参见图片以供参考
Most probably, you did not set the Storyboard ID of your LoginVC. Select the LoginVC in storyboard and set the storyboard ID as "loginview". See the image for reference
这篇关于AppDelegate didFinishLaunchingWithOptions launchOptions-以NSException Swift 3.0类型的未捕获异常终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!