Vik*_*ric 10 xcode uinavigationbar ios swift swiftui
问题是导航栏的标题和项目没有消失,这是一种意外行为。
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()
])
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题在于 .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()
])
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1441 次 |
| 最近记录: |