Как программно вернуться назад, используя вложенную навигациюDestination в SwiftUI

Я пытаюсь реализовать программную вложенную навигацию, используяNavigationStackиnavigationDestination(isPresented:). Но я не могу понять, почему я не могу вернуться к А (кнопка Вернуться к А не работает - ничего не происходит, когда я ее нажимаю). Кто-нибудь знает, что я делаю неправильно?

      struct Example: View {
    @State var aPresented: Bool = false
    @State var bPresented: Bool = false
    
    var body: some View {
        NavigationStack {
            Button("Go to A") {
                aPresented = true
            }
            .navigationDestination(isPresented: $aPresented, destination: { a })
        }
    }
    
    var a: some View {
        VStack {
            Text("A")
            Button("Go to B") {
                bPresented = true
            }
        }
        .navigationDestination(isPresented: $bPresented, destination: { b })
    }
    
    var b: some View {
        VStack {
            Text("B")
            Button("Go back to A") {
                bPresented = false
            }
        }
    }
}

0 ответов

Другие вопросы по тегам