[英]SwiftUI navigation bar title and items does not disappear when swiping back fails
The problem is that the title and the item of the navigation bar does not disappear which is an unexpected behaviour.问题是导航栏的标题和项目没有消失,这是一种意外行为。
struct DestinationView: View {
@State private var showingActionSheet = false
var body: some View {
Text("DestinationView")
.padding(.top, 100)
.navigationBarTitle(Text("Destination"), displayMode: .inline)
.navigationBarItems(trailing: Button(action: {
print("tapped")
}, label: {
Text("second")
}))
.actionSheet(isPresented: self.$showingActionSheet) { () -> ActionSheet in
ActionSheet(title: Text("Settings"), message: nil, buttons: [
.default(Text("Delete"), action: {
}),
.cancel()
])
}
}
}
The problem is that the .navigationBarTitle(), .navigationBarItems() modifiers and the .actionSheet() modifier are under each other in code.问题是 .navigationBarTitle()、.navigationBarItems() 修饰符和 .actionSheet() 修饰符在代码中是相互关联的。 (But it can be the .alert() or the .overlay() modifiers as well instead of .actionSheet())
(但它也可以是 .alert() 或 .overlay() 修饰符,而不是 .actionSheet())
The solution in this case:这种情况下的解决办法:
struct DestinationView: View {
@State private var showingActionSheet = false
var body: some View {
List {
Text("DestinationView")
.padding(.top, 100)
.navigationBarTitle(Text("Destination"), displayMode: .inline)
.navigationBarItems(trailing: Button(action: {
print("tapped")
}, label: {
Text("second")
}))
}
.actionSheet(isPresented: self.$showingActionSheet) { () -> ActionSheet in
ActionSheet(title: Text("Settings"), message: nil, buttons: [
.default(Text("Delete"), action: {
}),
.cancel()
])
}
}
}
Add添加
.navigationViewStyle(StackNavigationViewStyle())
to the NavigationView seems to fix it for me.到 NavigationView 似乎为我修复了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.