且构网

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

在 SwiftUI 中以编程方式使用 NavigationLink

更新时间:2023-12-04 21:19:10

我对 watchOS 没有任何经验,但我使用过 "isActive" 变体 NavigationLink 可满足类似应用需求.

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() })