ios - 登录成功后如何呈现不同的ViewController

标签 ios swift2 xcode7 segue viewcontroller

我使用 Firebase 作为后端,并编写了登录部分。当我使用测试帐户登录时,调试器打印“已登录:”。但是,当我尝试转到主视图 Controller 时,出现错误“ fatal error :在展开可选值时意外发现 nil"代码在 self.presentviewcontroller 行中断。这里做错了什么?

 if email != "" && password != ""
    {
        FIREBASE_REF.authUser(email, password: password, withCompletionBlock: {(error, FAuthData) -> Void in

            if error == nil
            {
                NSUserDefaults.standardUserDefaults().setValue(FAuthData.uid, forKey: "uid")

                print("logged in")
                self.logoutButton.hidden = false

                let storyboard = UIStoryboard(name: "Main", bundle: nil)
                let secondViewController = storyboard.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
                self.presentViewController(secondViewController, animated: true, completion: nil)

            }
            else{
                print("The user was not logged in")
            }

        })
    }
    else{
        let alert = UIAlertController(title: "ERROR", message: "Please Enter Email and Password", preferredStyle: .Alert)
        let action = UIAlertAction(title: "OK", style: .Default, handler: nil)
        alert.addAction(action)
        self.presentViewController(alert, animated: true, completion: nil)
    }

最佳答案

检查您的主 Storyboard是否将标识符 ViewController 设置为您的 ViewController。

关于ios - 登录成功后如何呈现不同的ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36336333/

相关文章:

ios - 对于 Xcode 和 iOS 开发,新的 Macbook Air 13"是否足够快?

javascript - 如何解决 ionic 应用程序中的文本区域选择问题?

android - 伪元素:after disapears on chrome mobile

ios - 需要从我的类中的函数返回数组

ios - 使用自动布局为 iPhone 4s 到 iPhone 6s plus 开发 UI

ios - iOS 中的 Android 重量(7 个按钮的宽度相等)

ios - 核心数据 - 编辑、增加和保存属性到已经存在的实体

ios - 将 UIPageViewController 添加到 View Controller 的容器 View

ios - 无法为只读属性升级到 swift 2.0 指定 setter

ios9 - 启用位码 Xcode 7.1