AppDelegate didFinishLaunchingWithOptions launchOptions - 以 NSException Swift 3.0 类型的未捕获异常终止 [英] AppDelegate didFinishLaunchingWithOptions launchOptions - terminating with uncaught exception of type NSException Swift 3.0

查看:25
本文介绍了AppDelegate didFinishLaunchingWithOptions launchOptions - 以 NSException Swift 3.0 类型的未捕获异常终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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

由于未捕获的异常而终止应用'NSInvalidArgumentException',原因:'Storyboard () 不包含带有标识符的视图控制器'登录查看'

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard () doesn't contain a view controller with identifier 'loginview''

libc++abi.dylib:以未捕获的异常类型终止NSException (lldb)

libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

推荐答案

很可能,您没有设置 LoginVC 的 Storyboard ID.在storyboard中选择LoginVC,将storyboard 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 类型的未捕获异常终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆