【发布时间】:2026-02-02 15:55:01
【问题描述】:
晚上好,
我有一个问题,当用户输入错误的电子邮件或输入错误的密码时,我需要显示错误。我需要在我的代码中添加什么? 我是软件开发新手,Sam 对 swift ui 不太熟悉,有人可以帮我吗?
@State var email = ""
@State var password = ""
var body: some View {
Image("ISD-Logo")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 185, height: 140)
.clipped()
.padding(.bottom, 75)
VStack {
TextField("Email", text: $email)
.padding()
.background(Color(UIColor.lightGray))
.cornerRadius(5.0)
.padding(.bottom, 20)
SecureField("password", text: $password)
.padding()
.background(Color(UIColor.lightGray))
.cornerRadius(5.0)
.padding(.bottom, 20)
Button(action: { login() }) {
Text("Sign in")
.font(.headline)
.foregroundColor(.white)
.padding()
.frame(width: 220, height: 60)
.background(Color.black)
.cornerRadius(35.0)
}
}
.padding()
}
// Login and error message
func login() {
Auth.auth().signIn(withEmail: email, password: password) { (result, error) in
if error != nil {
print(error?.localizedDescription ?? "")
} else {
print("success")
}
}
}
}
}
struct LoginView_Previews: PreviewProvider {
static var previews: some View {
LoginView()
}
}
【问题讨论】:
-
你试过什么?你做了什么研究?您的代码的哪一部分不起作用?通过Minimal Reproducible Example,我们可以帮助您解决问题,但 SO 不是代码编写服务。
标签: ios swift swiftui game-development