且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在SwiftUI中以编程方式使用NavigationLink

更新时间:2023-12-04 21:11:04

我对watchOS没有任何经验,但是我使用了.

I don't have any experience with watchOS, but I've used the the "isActive" variant of NavigationLink for similar app needs.

在初始视图中,定义一个@State var showOneLevelIn = false(或某些其他绑定),如果希望视图自动导航到第二级,则将该状态var设置为true. NavigationLink的标签为EmptyView(),因此在您的初始视图中将不可见.

In your initial view, define a @State var showOneLevelIn = false (or some other binding) and set that state var to true if you want the view to auto navigate to your second level. The label for the NavigationLink is an EmptyView() so it won't be visible in your initial view.

NavigationLink(destination: OneLevelInView(), isActive: $showOneLevelIn, label: { EmptyView() })