我尝试在 FireBase 登录后导航到主屏幕,但此代码在登录视图中显示了主屏幕视图。当登录成功时,我将 isReadyToNavigateToHomePage.toggle() 放入。当它为真时,我用它导航到主屏幕。
Button(action: {
let error = validateFields()
if error != nil{
errM = error!
showErrorAleart.toggle()
showError(error!)
print(error!)
}
else{
Auth.auth().signIn(withEmail: email, password: password) {(result, error) in
if error != nil {
errr = error!.localizedDescription
print(error!.localizedDescription)
}
else{
self.presentationMode.wrappedValue.dismiss()
print("successful log in")
isReadyToNavigateToHomePage.toggle()
}
}
}
}
){
HStack{
Spacer()
Text("Sign In")
.padding(.horizontal).padding(.vertical,5).padding(.trailing,20)
.background(Color.green)
.foregroundColor(.white)
.cornerRadius(10)
.padding(.top, 30)
.overlay(Image("signInBtn").resizable().frame(width: 12, height: 12).padding(5).background(Color.white).cornerRadius(5).offset(x: 35, y: 15))
Spacer()
}
if isReadyToNavigateToHomePage == true {
ContentView()
}
}
.alert(isPresented: $showErrorAleart){
Alert(title: Text("Warning"), message: Text(errM + errr), dismissButton: .default(Text("Ok")))
}
答案 0 :(得分:0)
我创建了一个虚假的导航链接,直到它切换,
NavigationLink(destination: ContentView(showHomeScreen: $showHomeScreen), isActive: $showHomeScreen){
Text("")
}.hidden()
else{
Auth.auth().signIn(withEmail: email, password: password) {(result, error) in
if error != nil {
errr = error!.localizedDescription
print(error!.localizedDescription)
}
else{
showHomeScreen.toggle()
print("login successcfully")
}
}
}
当我点击“登录”按钮时,它会切换并带我进入主屏幕。我找到了 视频网站上的解决方案。