Navigation bar issues on watchOS 7 Beta 6

I'm trying out the new NavigationView in watchOS 7 and having some issues with the navigation bar not showing up in child views.

Example

Code Block swift
import SwiftUI
struct ContentView: View {
    var body: some View {
        NavigationView {
            NavigationLink(
                destination: DestinationView(),
                label: {
                    Text("Destination")
                })
                .navigationTitle("Root")
        }
    }
}
struct DestinationView: View {
    var body: some View {
        NavigationView {
            Text("I'm here!")
                .navigationTitle("Destination")
        }
    }
}


Test setup

  • macOS 11.0 Beta 5

  • watchOS 7.0 Beta 6

  • Xcode 12.0 Beta 6

When running the app in the simulator or on the watch, the root view correctly displays the navigation bar, while the destination view does not.

Confusingly, the Xcode live preview does the opposite: The root view is missing the navigation bar, but the destination view is showing both the title and back button correctly.

The only mode in which the navigation bar is visible in both views is if I from Xcode select Preview on Device.

I'm new to SwiftUI and though I'm leaning toward this being a bug with the beta, I thought I'd check here to make sure I'm not just doing it wrong.

Accepted Reply

Turns out I was just doing it wrong. I hadn't noticed that the app scene had a top level NavigationView. I removed the NavigationViews from ContentView and DestinationView and it all started working.
  • I realize this is an old post, but the only relevant thing I see. I'm having the same problem (now with current versions of everything). I tried removing the NavigationViews as you mentioned but that didn't help. In fact, the NavigationView that is in the SceneBuilder (you are right that I hadn't noticed that one) isn't part of the Preview process. The preview starts with the "PreviewProvider" in the top-level ContentView so the NavigationView in the SceneBuilder has no effect on that.

    I tried adding NavigationView around the call to ContentView in the PreviewProvider, and that actually made my clicks really do navigation in the preview, but I still don't get the NavigationTitle in the preview! I tried hiding the NavTitle in the PreviewProvider code and that made no difference.

    If anyone has any further ideas on the OPs original topic (which is also my topic) I'd very much appreciate your feedback.

  • I'm having the same issue. I'm using Xcode 13.4.1 on an Apple Silicon Mac. Has anybody found the answer to this problem? Btw, the Landmarks SwiftUI example has the same issue, using the code that was issued by Apple.

Add a Comment

Replies

Turns out I was just doing it wrong. I hadn't noticed that the app scene had a top level NavigationView. I removed the NavigationViews from ContentView and DestinationView and it all started working.
  • I realize this is an old post, but the only relevant thing I see. I'm having the same problem (now with current versions of everything). I tried removing the NavigationViews as you mentioned but that didn't help. In fact, the NavigationView that is in the SceneBuilder (you are right that I hadn't noticed that one) isn't part of the Preview process. The preview starts with the "PreviewProvider" in the top-level ContentView so the NavigationView in the SceneBuilder has no effect on that.

    I tried adding NavigationView around the call to ContentView in the PreviewProvider, and that actually made my clicks really do navigation in the preview, but I still don't get the NavigationTitle in the preview! I tried hiding the NavTitle in the PreviewProvider code and that made no difference.

    If anyone has any further ideas on the OPs original topic (which is also my topic) I'd very much appreciate your feedback.

  • I'm having the same issue. I'm using Xcode 13.4.1 on an Apple Silicon Mac. Has anybody found the answer to this problem? Btw, the Landmarks SwiftUI example has the same issue, using the code that was issued by Apple.

Add a Comment