1

I want to generate the function to my button to be able to make that when I press it it goes to a new view but I do not know how I already have more than 3 hours trying

enter image description here

1
  • 3
    Btw please post your code as text, not an image Commented May 24, 2021 at 15:47

1 Answer 1

2

There's a couple problems:

  1. If you want to use programmatic navigation (using a custom button), you'll need an @State to control whether the NavigationLink is active or not.
  2. NavigationLink needs to be somewhere inside a NavigationView.
  3. You also need a VStack, because NavigationView should only wrap around a single View.
struct ContentView: View {
    @State var isPresenting = false /// 1.
    
    var body: some View {
        NavigationView { /// 2.
            VStack { /// 3.
                Button("comenzar") {
                    isPresenting = true
                }
                //        .buttonStyle(fillesRundedCornerButtonStyle())
                
                NavigationLink(destination: HolaView(), isActive: $isPresenting) { EmptyView() }
            }
        }
    }
}

struct HolaView: View {
    var body: some View {
        Text("Hola, como estas?")
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.