SwiftUI - 按钮操作未激活

时间:2021-05-16 06:23:03

标签: xcode swiftui

我是 SwiftUI 的新手,正在尝试让 Button 工作。

我在 macOS Catalina 10.15 上使用 XCode 12.4。

以下是我尝试过的代码,并使用了 3 种不同形式的按钮创建。 他们都没有工作。

我做了 DEBUG PREVIEW,打开了 CONSOLE,在 CONSOLE 上没有看到任何消息。 我尝试使用调试器,它显示控制进入 print() 语句,但实际上没有打印任何内容。

我在这里遗漏了什么?

    VStack {

        Button("My Button - 1") {
            print("Click - 1")
        }
        
        Button(action: {
                print("Click-2")
               }){
                    Text("My Button - 2")
               }

        Button(action: {
                print("Click - 3")
               },
               label: {
                    Text("My Button - 3")
               })
    }

0 个答案:

没有答案