6

I'm trying to add a NavigationLink at the top of the screen, but once I click it, it prompts me to the result and the Back button disappears.

SwiftUI Code:

NavigationView {
    VStack {
        NavigationLink (destination: Text("COOL")) {
            Text("COOL")
        }

        Spacer()
    }
    .navigationBarHidden(true)
    .navigationBarTitle(Text("Home"))
    //.edgesIgnoringSafeArea([.top, .bottom])
}

The back button disappears after clicking on the NavigationLink: https://gyazo.com/9d39936c849f570a05687e41096ddeca

2 Answers 2

1

There is some glitch IMHO, when you use both .navigationBarHidden(true) and .navigationBarTitle(Text("Some text)). If you remove the last one, back button works as usual. Nevertheless I tried to return back button in your code snippet. It still has glitch while returning to first view, but back button don't disappear. I hope it will help and you will go further from here:

struct NotHiddenBackButton: View {

    @State var hiddingNavBar = true
    @State var goToSecondView = false

    var body: some View {

        NavigationView {

            NavigationLink(destination: ViewWithBackButton(hiddingNavBar: $hiddingNavBar), isActive: $goToSecondView) {

                VStack {
                    Text("COOL")
                        .onTapGesture {
                            self.hiddingNavBar = false
                            self.goToSecondView = true
                    }
                    Spacer()

                }


            }
            .navigationBarHidden(hiddingNavBar)
            .navigationBarTitle(Text("Home"))
        }


    }

}

struct ViewWithBackButton: View {

    @Binding var hiddingNavBar: Bool
    var body: some View {

        Text("Second view")
            .navigationBarTitle("Second view")
            .onDisappear() {
                self.hiddingNavBar = true
        }

    }

}
1
  • 1
    I'm not using navigationBarHidden anywhere in my app, and am getting this missing back button. Mar 13, 2021 at 23:37
-2

I believe this was a bug that has now been fixed in iOS 14

3
  • Welcome to SO. It would be helpful if your answer included a reference to the bug or fix.
    – seshadri_c
    Sep 29, 2020 at 5:21
  • 1
    Sorry about that, I haven't tracked down a reference for this, but I did test the bug out on Xcode 11 / 12 and it appears to be resolved on 12.
    – dcelentano
    Sep 29, 2020 at 13:18
  • 3
    I'm seeing it using iOS 14. Mar 13, 2021 at 23:37

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.