我对 NagivationBarTitle 有疑问。
我有一个视图(第一个视图),我称之为另一个视图(第二个视图)。在第二个视图中,我有一些可以选择的照片。如果未选择图像,则导航栏标题为“图像”。如果我选择了图像,我的标题是“x Images selected”。如果我选择了图像,我可以按下一个按钮,该按钮将显示一个 ActionSheet。
问题是,当显示操作表时,标题会回到“图像”。如何在点击之前保留 ActionSheet 中的标题(“x Images selected”)?
显示操作表时的一些代码示例:
第一视角:
struct FirstView: View {
var body: some View {
VStack (alignment: .leading) {
List {
AnotherView(param: param)
.navigationBarItems(trailing:
NavigationLink(destination: SecondView()) {
Image(name: "search")
}
)
}
}
}
}
第二种观点:
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()
])
}
}
}
}