1
votes

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

2

2 Answers

2
votes

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

.navigationBarTitle("", displayMode: .inline)
.navigationBarHidden(false)
0
votes

Just remove this line:

.navigationBarTitle(Text("_"))

from VideoDetailed.