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

查看:289
本文介绍了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()不包含带有标识符的视图控制器 'loginview'

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.在情节提要中选择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类型的未捕获异常终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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