Friday, May 1, 2026
HomeiOS Developmentios - SwiftUI cannot conceal navigationBar on pushed view when earlier view...

ios – SwiftUI cannot conceal navigationBar on pushed view when earlier view search bar lively

[ad_1]

I’ve an issue when pushing to a brand new view with a search bar lively.

Within the pushed view I would like the navigation bar to be hidden. It really works in all instances besides when the search subject is lively on the pushing view AND the navigation type is StackNavigationViewStyle.

Within the instance mission beneath if you choose a row, the brand new view is pushed and the navigation bar is hidden as anticipated. Nevertheless, when you first choose the search bar to make it lively after which press a row, the navigation bar is now not hidden on the pushed view.

Eradicating the StackNavigationViewStyle, every thing will work superb nonetheless I have to have StackNavigationViewStyle.

struct ContentView: View {
    
    @State var searchString = ""
    
    var physique: some View {
        NavigationView {
            Record {
                NavigationLink {
                    PushedView()
                } label: {
                    Textual content("Press Me")
                }
            }
            .listStyle(PlainListStyle())
            .searchable(textual content: $searchString)
            .navigationTitle("First View")
        }
        .navigationViewStyle(StackNavigationViewStyle())
    }
}

struct PushedView: View {
    
    @Setting(.presentationMode) var presentationMode: Binding<PresentationMode>
        
    var physique: some View {
        Button {
            self.presentationMode.wrappedValue.dismiss()
        } label: {
            Textual content("Pop View")
        }
        .navigationTitle("Second View")
        .navigationBarHidden(true)
    }
}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments