【发布时间】:2021-09-28 14:10:20
【问题描述】:
我通过按“展示我的模式”按钮来展示带有fullScreenCover 的模式视图:
struct ContentView: View {
@State var presentMyModal = false
var body: some View {
Text("Hello, world!")
.fullScreenCover(isPresented: $presentMyModal) {
MyModalView()
}
Button(action: { presentMyModal = true },
label: { Text("present my modal")})
}
}
然后我想用NavigationLink从这个模态推送一个新视图:
struct MyAlertView: View {
@State var pushNavigationLinkedView = false
var body: some View {
Text("MyAlertView")
.padding()
Button(action: { pushNavigationLinkedView = true },
label: { Text("push navigation linked view")})
NavigationLink(destination: NavigationLinkedView(),
isActive: $pushNavigationLinkedView) {
EmptyView()
}
}
}
这是我的NavigationLinkedView:
struct NavigationLinkedView: View {
var body: some View {
Text("NavigationLinkedView")
.padding()
}
}
但是当我按下“推送导航链接视图”按钮时没有任何反应。
那么苹果指南是否允许从模态视图推送带有NavigationLink 的视图?如果是,最好的方法是什么?
在 iOS15 和 XCode 13 上测试
【问题讨论】: