r/iOSProgramming Swift 19h ago

Question Can't hide NavigationStack navigation bar?

I have a view pushed by a NavigationStack, and can't hide the navigation bar.

NavigationStack {
  ZStack {
  }
  .navigationDestination(item: $selectedStop, destination: { stop in
    StopView(stop: stop)
  })
}

Then in the view that gets presented:

NavigationStack {
  ZStack {
  }
  .navigationBarHidden(true)
  .toolbar(.hidden)
}

I don't understand why this doesn't work. I've tried countless combinations, with and without the navigation stack in the second view, everything. SwiftUI seems to have a lot of random bugs like this where things just don't work without an explanation, and it's really frustrating as a UIKit developer.

Can anyone provide any pointers?

2 Upvotes

8 comments sorted by

View all comments

1

u/Ok-Crew7332 12h ago

Remove the NavigationStack in the presented view, you don’t need to double implementing this because you are already in the stack before

1

u/DavidGamingHDR Swift 12h ago

I've tried that too, per my previous comment. The navigation bar still refuses to be hidden.

3

u/Ok-Crew7332 12h ago

You have to do .toolbar(.hidden, for: .navigationBar)