SwiftUi - hide "Back" button and navigation bar (appears for a fraction of second)
Asked Answered
B

2

5

I'm using this code to hide a navigation bar and Back button but when the view is loaded i still can see the back button for a fraction of second and then it disappears. Is there any way to prevent it from being shown?

var body: some View {
    NavigationView {
        NavigationLink(destination: DeferView { WeekView(journey: self.launcher.completeJourney!) }, isActive: self.$launcher.readyJourney ) { EmptyView () }
        .navigationBarHidden(true)
        .navigationBarTitle("")
    }
}

Thank you in advance,

Bassorilievo answered 2/6, 2020 at 17:44 Comment(0)
T
4

Add the same modifiers also for link destination,

var body: some View {
    NavigationView {
        NavigationLink(destination: DeferView { WeekView(journey: self.launcher.completeJourney!) }
                                    .navigationBarHidden(true)   // here !!
                                    .navigationBarTitle("")      // here !!

              , isActive: self.$launcher.readyJourney ) { EmptyView () }
        .navigationBarHidden(true)
        .navigationBarTitle("")
    }
}
Tellurium answered 2/6, 2020 at 17:58 Comment(1)
This doesn't work for me do you have any other suggestion? My code: struct FirstSwiftUIView: View { var body: some View { VStack { Text("First SwiftUi View") NavigationLink { SecondSwiftUIView() } label: { Text("Next View") } } .navigationBarBackButtonHidden(true) .navigationBarTitle("") } }Boycott
A
1

I was able to remove it by adding .navigationBarBackButtonHidden(true) to my Destination View where I am navigating and want to hide navigationBar.

In the above code, you need to add navigationBarBackButtonHidden modifier in WeekView in order to hide navigation and back bar button.

struct ViewB: View { 
    var body: some View {
        VStack {

        }
        .navigationBarBackButtonHidden(true)
    }
}

In your case, View B is WeekView().

Augustineaugustinian answered 6/4, 2024 at 17:27 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.