1

I'm trying to make a simple app using SwiftUI using NavigationView and the last View is a video player (which I obviously don't want to have a navigationBar). The thing is that every other View leading to the player has navigationBarTitle and it just stays.

What I have:

ContentView :

var body: some View {
    NavigationView {
        VStack {
            Text("Sample")
            DetailedView(data: CustomData.sample)
        }
        .navigationBarTitle(Text("Main"))
    }
}

DetailedView:

@ObservedObject var data: CustomData

var body: some View {
    ScrollView(.vertical, showsIndicators: false) {
        VStack {
            ForEach(data.array) { videoData in
                NavigationLink(destination: VideoDetailed(videoData: videoData)) {
                    VideoRow(episode: episode)
                }
            }
        }
    }
}

VideoDetailed:

@ObservedObject var videoData: VideoData

var body: some View {
    VStack {
        NavigationLink(destination: PlayerContainerView(url: videoData.url)
              .navigationBarBackButtonHidden(true)
              .navigationBarTitle(Text("_"))
              .navigationBarHidden(true)){
                Image(systemName: "play.fill")
                    .resizable()
                    .foregroundColor(.white)
                    .aspectRatio(contentMode: .fit)
                    .shadow(radius: 5)
                    .frame(maxWidth: 50)
            }
        Text(videoData.description)
        Spacer()
    }
    .navigationBarTitle(Text(videoData.title), displayMode: .inline)
}

As a result of this code I get no back button and a "_" for title with a navigation bar

Steph
  • 11
  • 1
  • 2

2 Answers2

3

You need to set the title to an empty string and the displayMode to inline for it to hide.

.navigationBarTitle("", displayMode: .inline)
.navigationBarHidden(false)
Brett
  • 1,647
  • 16
  • 34
0

Just remove this line:

.navigationBarTitle(Text("_"))

from VideoDetailed.

LuLuGaGa
  • 13,089
  • 6
  • 49
  • 57
  • It didn't help. In fact, as far as I understood, if there is no title added you can't hide the bar at all (cuz there is nothing to hide? I don't see the logic tho). – Steph Oct 03 '19 at 23:07
  • 1
    If there is no title there is still a bar, which contains the back button. Somehow you need to hide both the bar and the button, which seems not very logical to me either. The code you provided is not enough to copy and paste into Xcode, so I have based my answer on a simple stack of view I have built. If my solution doesn't work for you, it might be that there is something about your `PlayerContainerView`, that makes the title appear. – LuLuGaGa Oct 04 '19 at 07:07