我想Textfield在SwiftUI点击按钮时设置文本。我尝试使用@State变量但它给出错误
尝试下面的代码(在 Xcode 中测试:11.2.1)
struct ContentView: View {
@State var name: String = ""
var body: some View {
VStack {
TextField("Please enter", text: $name)
Button(action: {
self.name = "Hello text"
}) {
Text("Press")
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5072 次 |
| 最近记录: |