Pavel Gatilov
Pavel Gatilov

Reputation: 2590

SwiftUI navigationBarHidden doesn't work and throws error

I am pushing next view with navigation link

        NavigationLink(destination: DetailsView()
            .navigationBarTitle("")
            .navigationBarHidden(true),
                       isActive: $isDetailsActive) {
            EmptyView()
        }

I tried the same inside details view too. All I am getting is empty Navigation Bar on Details View and error in terminal:

"changing items while animating can result in a corrupted navigation bar"

Upvotes: 4

Views: 1792

Answers (3)

Christo Jovner
Christo Jovner

Reputation: 19

Try:

 NavigationView {

    some code {..}

   .navigationBarTitle("")
   
   .navigationBarHidden(true)

}

It seems that the navigationBarTitle seems to be set at (""), for the .navigationBarHidden(true) to work within a NavigationView (Xcode Version 13)

Upvotes: 1

zgluis
zgluis

Reputation: 3375

I hide my navigation bar using .onAppear and .onDisappear, you can place those modifiers in your parent view or in DetailsView(), look:

NavigationView {
    VStack {
        Text("Hello World")
    }
    .navigationBarTitle("")
    .navigationBarHidden(self.isNavBarHidden)
    .onAppear {
        self.isNavBarHidden = true
    }.onDisappear {
        self.isNavBarHidden = false
    }
}

Upvotes: 1

grow4gaurav
grow4gaurav

Reputation: 3305

The error indicates that you should not push or pop new views on the navigation controller until it’s finished with the last push or pop.

Upvotes: 1

Related Questions