我在代码中通过导航栏按钮呈现模式表:
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")
})
})
})
}
}
但导航栏不会出现在模式表中,如下所示。
我做错了什么,如何在模式表上放置导航栏?
您必须将模态视图包装在NavigationView
像这样
@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: {}))
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)