当我的Textfield为空时,我尝试向按钮插入一个简单的警告,但是我收到错误消息Alert.Button不能转换为‘Alert.Button?’。
我会说我的代码是100%正确的,但是..。Xcode不在我这边..。
这是我的密码..。
struct ContentView : View {
@State private var name = String()
@State private var pw = String()
@State private var myAlert = false
var body: some View {
NavigationView {
ZStack{
VStack{
//deleted code//
Button(action: {
if self.name == self.fileName
{
print("Hey \(self.name) - your password is \(self.pw)")
} else {
if self.name.isEmpty && self.pw.isEmpty {
self.myAlert = true
print("broken!")
}
}
.alert(isPresented: $myAlert) {
Alert(title: Text("ERROR!"), message: Text("Username und Password are empty"), dismissButton:.default(Text("Ok")))
}
})
//deleted code//
}}}}}有人知道错误在哪里吗?我找不到他们。
谢谢你的帮忙!
发布于 2020-02-28 21:39:39
1)没有fileName?
( 2)按钮缺少标签:
Button(action: {...}) {
//Label here
}https://stackoverflow.com/questions/60459497
复制相似问题