简体   繁体   中英

How to navigate between view controllers on a button action in swiftui?

I want to navigate between the login screen to sign up Screen with the help of button action.

   Button(action: {

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

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

You can create navigation link and set properties to show it like button: Here is my code:

    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)
        }
    }

Here is how it looks:

在此处输入图片说明

Hope it helps..Good Luck :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM