iSp*_*n17 11 ios swift 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")
})
})
})
}
}
Run Code Online (Sandbox Code Playgroud)
但是导航栏没有出现在模态表中,如下所示。
我做错了什么,你如何在模态表上放置导航栏?
LuL*_*aGa 17
你必须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: {}))
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5593 次 |
| 最近记录: |