SwiftUI NavigationBar Title not present as it is when ActionSheet is present

185 Views Asked by At

I have a problem regarding NagivationBarTitle.

I have a view (first view) from which I call another one (second view). In the second view I have some photos which I can select. If no Images are selected the NavigationBar title is "Images". If I have images selected I have the title like "x Images selected". If I have images selected I can press a button which will display an ActionSheet.

The problem is that when the action sheet is shown the title is going back to "Images". How can I preserve the title in ActionSheet as it was before tapping ("x Images selected")?

Some example of code when action sheet is shown:

First View:

struct FirstView: View {
    var body: some View {
            VStack (alignment: .leading) {
                List {
                    AnotherView(param: param)
                    .navigationBarItems(trailing:
                    NavigationLink(destination: SecondView()) {
                            Image(name: "search")
                        }
                    )
                }
            }
    }
}

Second View:

struct SecondView: View {
    @State private var imagesSelected: Int = 0
var body: some View {
    VStack {
        List {
                // here is a grid of items. every time an item is clicked a
                // counter in encreasing
                when item clicked: imagesSelected++
        }
        .navigationBarTitle("\(self.imagesSelected) Files selected")
        .actionSheet(isPresented: $showingActionSheet) {
            ActionSheet(title: Text("Delete Images"), buttons: [
                .destructive(Text("Delete")){
                    // Some action
                },
                .cancel()
            ])
        }
    }
}

}

0

There are 0 best solutions below