如何在swiftui中的按钮操作之间在视图控制器之间导航?

时间:2020-02-27 05:36:30

标签: button navigation swiftui viewcontroller

我想借助按钮操作在登录屏幕之间导航以注册屏幕。

   Button(action: {

                NavigationLink(destination:SignUpScene()){
                   Text("Show Detail View")
                                  }

                print("Join button tapped!!")
                   })

1 个答案:

答案 0 :(得分:0)

您可以创建导航链接并设置属性以使其像按钮一样显示: 这是我的代码:

    var body: some View {
        NavigationView {

            //Button to navigate to another page
            NavigationLink(destination: AlertView()) {
                Text("GO TO ALERT")
                    .padding(15)
                    .frame(minWidth: 0, maxWidth: .infinity)
                    .background(Color.red)
                    .foregroundColor(Color.white)
                    .cornerRadius(4)
            }
            .padding([.leading, .trailing], 30)
            .padding([.top], 21)
            .frame(height: 50)
        }
    }

这是它的外观:

enter image description here

希望有帮助。祝您好运:)