0

I have two different views, one with a NavigationView and another one that i want without NavigationView but since i put it in a NavigationLink I can still see it with a button to go back to the first view. Here's the code:

struct MainView: View {
    var body: some View {

    NavigationView {
        NavigationLink(destination: SecondView()) {
            Text("Go to SecondView")

        .navigationBarTitle("MainView")
        }
    }
}

struct SecondView: View {
    var body: some View {

    Text("This is the SecondView")
}

I want to hide the Navigation Bar in the Second View but leaving a button to go back. I don't know if i can keep the button that was already displayed in the Navigation Bar or should i make a new one...in this case how can I add one to go back to the previous view?

xmetal
  • 681
  • 6
  • 16
  • You can refer to this answer https://stackoverflow.com/a/57518324/7420795 – user7420795 May 10 '20 at 19:25
  • Thank you so much! I made a binding property that changes when the view of navigationlink appears and works perfectly – xmetal May 10 '20 at 20:24
  • By the way do you know how can I add a back button now that the navigation Bar is gone? – xmetal May 10 '20 at 20:25
  • You can add a custom button for this. var btnBack : some View { Button(action: { self.presentationMode.wrappedValue.dismiss() }) { HStack { Image("ic_back") // set image here .aspectRatio(contentMode: .fit) .foregroundColor(.white) Text("Go back") } } } https://stackoverflow.com/a/57594164/7420795 – user7420795 May 11 '20 at 10:23
  • Amazing, thank you for helping! I actauuly saw that thread before but I couldn't understand how that was working – xmetal May 11 '20 at 15:30

0 Answers0