Search code examples
swiftuinavigationview

How to hide NavigationView when push to another Screen in SwiftUI


I have 2 screens CourseList and second CourseDetail. where I'm able to hide navigationView on First/Initial Screen by blow code.

    var body: some View {
    NavigationView  {
        List (networkManager.courses)  { course in
            NavigationLink(destination: CourseDetails(course: course)) {
                CourseRow(course: course)
            }
            .padding(EdgeInsets(top: 0, leading: -8, bottom: 0, trailing: 0))
        }
        .navigationBarTitle(Text("Courses"), displayMode: .inline)
        .navigationBarHidden(true) //It Hides NavigationView

    }
}

On Second Screen Course Detail I want to hide Navigationbar.


Solution

  • Add in your CourseDetails view:

    .navigationBarTitle("")
    .navigationBarHidden(true)
    

    Sometimes you first need to set the title to be able to hide the navbar.