【发布时间】:2021-07-10 12:16:27
【问题描述】:
如何在 SwiftUI 中将 TextField 添加到 .alert() 函数?我只能找到需要 Swift 的解决方案,而不是 SwiftUI。
.alert(isPresented:$showingAlert) {
Alert(
title: Text("What is your name?"),
message: Text("Fill in your name in the TextField beow"),
primaryButton: .default(Text("OK")) {
print("Opening...")
},
secondaryButton: .cancel() {
print("cancelled)
}
)
}
【问题讨论】:
-
使用 UIViewControllerRepresentable 创建警报包装器?
-
我只知道 SwiftUI..
-
好的,我会发布一个答案然后检查。
-
你有没有试过这里的解决方案stackoverflow.com/a/56732240/9416553
-
这能回答你的问题吗? How to add a TextField to Alert in SwiftUI?