0

首先....我是 swift 4.0 / Xcode 10.1 开发的新手。我遇到的设计问题是我创建了一个带有firebase身份验证的登录页面(有效),我目前正在尝试找出设置它的最佳实践,以便我的“登录”按钮位于右上角完成 firebase 身份验证过程后,页面将更改为“注销”。我附上了一张应该有帮助的图片。我似乎找不到任何关于这类事情的最佳实践的文档...... 图片在这里

我的猜测是我设置了第二个视图控制器,但在用户通过身份验证后“受保护”。但是,如果有另一种/更好的方法来完成这个我不知道的情况,我会问这个问题吗?

@IBAction func login(_ sender: UIBarButtonItem) {
    if Auth.auth().currentUser != nil {
    } else {
        let authUI = FUIAuth.defaultAuthUI()
        authUI!.delegate = self
        let providers: [FUIAuthProvider] = [
            FUIGoogleAuth()]

        authUI?.providers = providers
        let authViewController = authUI!.authViewController()
        self.present(authViewController, animated: true, completion: nil)
        }
        do {
            try Auth.auth().signOut()
        } catch let error as NSError {
            print(error.localizedDescription)
        }
    }


}

// 为登录按钮添加变量作为布尔值,如果登录为真和假,则为值添加按钮。我现在正在寻找有关如何调用上面的登录功能的帮助。抱歉,我对 swift 4.0 很陌生。非常感谢任何帮助

    @IBAction func pressedNavButtonRight(sender: UIBarButtonItem) {
    if isLogin
    {isLogin = false
        self.navigationItem.rightBarButtonItem! = UIBarButtonItem(title: 
"Logout", style: UIBarButtonItemStyle.done, target: self, 
action:"pressedNavButtonRight")
    }
    else
    {
        isLogin = true
        self.navigationItem.rightBarButtonItem! = UIBarButtonItem(title: 
"Login", style: UIBarButtonItemStyle.plain, target: self, 
 action:"pressedNavButtonRight")
    }
}
4

1 回答 1

0

这已经解决了,我想通了。我能够使用布尔值来获得所需的结果。我可能会稍后为任何感兴趣的人发布代码

于 2019-01-21T06:14:48.350 回答