[英]NavigationLink doesn't work when View is embedded in a modal sheet
Weird problem.奇怪的问题。 I have a view called
SecondView
which has a NavigationLink
like so:我有一个名为
SecondView
的视图,它有一个像这样的NavigationLink
:
struct SecondView: View {
var body: some View {
NavigationStack {
List {
Section {
EmptyView()
}
//PowerUp Section
Section {
VStack {
NavigationLink (destination: Powerup()) {
Text("2")
}
.isDetailLink(false)
}
}
}
}
}
}
This view is embedded in a modal view.此视图嵌入在模态视图中。 The
NavigationLink
works fine when I preview SecondView
on Xcode but doesn't when I preview the modal sheet.当我在
SecondView
上预览SecondView时, NavigationLink
工作正常,但当我预览模态表时,NavigationLink 工作正常。 Doesn't work on an actual device or simulator too.也不适用于实际设备或模拟器。 Looks like a hierarchy problem or something like this.
看起来像是层次结构问题或类似问题。 Can someone tell me where I'm wrong?
有人可以告诉我哪里错了吗? Thanks.
谢谢。
Since the old NavigationLink(destination:)
has some severe limitations, you are supposed to use NavigationLink(value:)
and .navigationDestination(for:)
when using the new NavigationStack
, eg由于旧的
NavigationLink(destination:)
有一些严重的限制,您应该在使用新的NavigationStack
时使用NavigationLink(value:)
和.navigationDestination(for:)
,例如
NavigationStack {
List(parks) { park in
NavigationLink(park.name, value: park)
}
.navigationDestination(for: Park.self) { park in
ParkDetails(park: park)
}
}
Auto-solved the problem.自动解决了问题。 I was embedding
SecondView
in the modal in the wrong way.我以错误的方式将
SecondView
嵌入到模态中。 The view should be wrapped in a NavigationView
and a NavigationStack
first.视图应首先包装在
NavigationView
和NavigationStack
中。 Maybe it's helpful to someone else.也许这对其他人有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.