我想显示详细信息页面上打开的应用程序与后退按钮。单击“后退”按钮时,应显示帐户列表。就像iOS默认的邮件应用程序一样。我使用NavigationStack、NavigationLink和.navigationDestinatiion请参考下面的gif。先谢谢你了。
NavigationStack
NavigationLink
.navigationDestinatiion
ss2ws0br1#
您可以使用NavigationStack来实现这一点。下面是示例代码。
class Coordinator: ObservableObject { @Published var path: [String] = [] } struct Testing: View { @StateObject var coordinator = Coordinator() var body: some View { NavigationStack(path: $coordinator.path) { DefaultView() } .environmentObject(coordinator) } } struct DefaultView: View { @EnvironmentObject var coordinator: Coordinator @State private var isDetailViewActive = true var body: some View { Text("Hello world") .onAppear { if isDetailViewActive == true { self.isDetailViewActive = false coordinator.path.append("DetailsView") } } .navigationDestination(for: String.self) { view in DetailsView() } } } struct DetailsView: View { var body: some View { NavigationView { Text("How are you") } } }
1条答案
按热度按时间ss2ws0br1#
您可以使用NavigationStack来实现这一点。
下面是示例代码。