【问题标题】:Firebase User signOut in swift list button快速列表按钮中的 Firebase 用户注销
【发布时间】:2020-10-05 04:30:57
【问题描述】:

我正在尝试在我的列表视图中设置一个按钮,以允许用户从设备上退出其帐户。我关注了有关设置登录和注销的视频,我对这些很有信心,但我不确定自己做错了什么。

这是我的代码:

struct SettingsAccountView: View {
    @EnvironmentObject var session: SessionStore

    func getUser() {
        session.listen()
    }

    var body: some View {
        List {
            Section {
                Button(action: {
                    print("Change USER email")
                            }) {
                    SettingsCell(title: "Change Email", imgName: "envelope.fill", clr: Color("Waterfall"))
                }

                Button(action: {
                    print("Change USER password")
                                    }) {
                    SettingsCell(title: "Change Password", imgName: "eye.slash.fill", clr: Color("Waterfall"))
                }

                Button(action: {
                    print("Change USER Photo")
                            }) {
                    SettingsCell(title: "Change Profile Photo", imgName: "camera.rotate", clr: Color("Waterfall"))
                }
            }

            Section {
                Button(action: session.signOut) {
                    print("SignOut")
                }) {
                    SettingsCell(title: "Sign Out", imgName: "person.crop.circle.badge.xmark", clr: .red)
                }
                Button(action: {
                    print("Delete MY Account")
                            }) {
                    SettingsCell(title: "Delete My Account", imgName: "trash.circle", clr: .red)
                }
            }

        }.listStyle(GroupedListStyle())
            .environment(\.horizontalSizeClass, .regular)
            .navigationBarTitle("Account", displayMode: .inline)
    }
}

struct SettingsAccountView_Previews: PreviewProvider {
    static var previews: some View {
        SettingsAccountView()
    }
}

【问题讨论】:

    标签: swift firebase firebase-authentication swiftui swiftui-list


    【解决方案1】:

    可能是您错误地为此按钮指定了action 参数:

    Button(action: session.signOut) {
        print("SignOut")
    }) {
        SettingsCell(title: "Sign Out", imgName: "person.crop.circle.badge.xmark", clr: .red)
    }
    

    看起来您添加了一个额外的闭包作为操作块。你的动作参数可以是一个函数(如session.signOut)或一个闭包(如{ print("SignOut") })。不可能两个都是。

    试试这个代码:

    Button(action: {
        self.session.signOut
        print("SignOut")
    }) {
        SettingsCell(title: "Sign Out", imgName: "person.crop.circle.badge.xmark", clr: .red)
    }
    

    【讨论】:

      猜你喜欢
      • 2015-01-25
      • 1970-01-01
      • 2022-07-07
      • 1970-01-01
      • 2015-08-16
      • 2019-01-27
      • 1970-01-01
      • 1970-01-01
      • 2016-12-20
      相关资源
      最近更新 更多