ios - 模态表可以在 SwiftUI 中有导航栏吗?
问题描述
我在我的代码中从导航栏按钮呈现模式表:
struct MainPage : View {
@State var isModalSheetShown: Bool = false
var body: some View {
VStack {
[...]
}
.navigationBarItems(trailing: HStack {
Button(action: { self.isModalSheetShown = true }) {
Text("Add")
}
})
.sheet(isPresented: $isModalSheetShown, content: {
VStack {
[...]
}
.navigationBarItems(trailing: HStack {
Button(action: { ... }) {
Text("Done")
})
})
})
}
}
但是导航栏没有出现在模态表中,如下所示。
我在做什么错,你如何在模态表上放置导航栏?
解决方案
你必须NaviagtionView
像这样包装你的模态视图
@State var isModalSheetShown: Bool = false
var body: some View {
VStack {
Text("Main")
}
.navigationBarItems(trailing: Button("Add",
action: { self.isModalSheetShown = true }))
.sheet(isPresented: $isModalSheetShown) {
NavigationView {
VStack {
Text("Modal")
}
.navigationBarItems(trailing: Button("Done",
action: {}))
}
}
}
推荐阅读
- git - 如何用git找到一行所属的函数?
- java - 带有 java Apache POI 的彩色标题单元格
- entity-framework - VSTS/DevOps:隐藏文件签出到另一个工作区
- django - Graphene Django - 具有一对多关系外键的突变
- javascript - 如何将 hotjar 与 ember 一起使用?
- wpf - Winforms上的Bing Maps WPF控件,处理点击事件
- javascript - 需要 onBlur 事件的帮助
- docker - 如何更改 docker 容器日志的保存位置?
- javascript - ReactJS - SVG - 交互式时间线
- android - Android Studio - 增强现实,在图像目标上渲染 3D 模型