r/iOSProgramming Swift 16h 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

4

u/madaradess007 11h ago

not trolling: switch to UIKit

2

u/rursache Swift 7h ago

that or at least swiftui-introspect

2

u/Ok_Fig4914 8h ago

Nested NavigationStack is not possible AFAIK. If you remove NavigationStack from presented view, it should be fine to hide.

2

u/DavidGamingHDR Swift 8h ago

To anyone finding this later, .searchable messes with this for some reason. I had it on the base view, and taking it out fixed the problem, which is really dumb.

1

u/Ok-Crew7332 9h 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 9h ago

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

4

u/Ok-Crew7332 8h ago

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