问题在于导航栏的标题和项目没有消失,这是意外行为。
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()
])
}
}
}
答案 0 :(得分:1)
问题在于.navigationBarTitle()、. navigationBarItems()修饰符和.actionSheet()修饰符在代码中位于彼此之下。 (但也可以是.alert()或.overlay()修饰符,而不是.actionSheet())
在这种情况下的解决方案:
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()
])
}
}
}
答案 1 :(得分:-1)
添加
.navigationViewStyle(StackNavigationViewStyle())
到NavigationView似乎可以为我修复它。