如何为按钮创建一个函数来打印控制台中文本字段中键入的数据
struct ContentView: View {
@State private var name : String = ""
var body: some View {
NavigationView{
Form{
Button(action: {
print(Textfield)
}) {
Text("Salvar")
}
我需要打印在 Textfield
中输入的结果。
struct ContentView: View {
@State private var name : String = ""
var body: some View {
NavigationView{
Form{
Button(action: {
print(Textfield)
}) {
Text("Salvar")
}
I need to print the result typed at Textfield
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您混淆了视图
TextField
,它允许您使用存储输入结果的变量输入文本。您无法打印您键入的视图,但可以打印变量的值。所以:You are confusing the view,
TextField
, which allows you to input text with the variable which stores the result of the input. You can't print the view into which you type, but you can print the value of the variable. Therefore: