swiftui:跳过了 NavigationStackHostingController 包含,因为源和目标为零

问题描述 投票:0回答:1

在 Apple Watch 平台的 SwiftUI 中使用 NavigationStack 时出现以下错误。

NavigationView 效果很好,但没有达到目的。

不确定发生了什么问题。

如有任何帮助,我们将不胜感激。

Xcode:15.4 目标:Apple Watch OS 10.4

<NavigationHostingControllerCache>: MISS at depth 0 in free stack
[NavigationHostingControllerCache_UIKit] <_TtGC7SwiftUI32NavigationStackHostingControllerVS_7AnyView_: 0x1540f200> containment skipped because source and destination were `nil`
<NavigationHostingControllerCache>: HIT at depth 0 in free stack
<NavigationHostingControllerCache>: MISS at depth 1 in free stack
<NavigationHostingControllerCache>: MISS at depth 2 in free stack
[NavigationHostingControllerCache_UIKit] <_TtGC7SwiftUI32NavigationStackHostingControllerVS_7AnyView_: 0x1540f200>     containment skipped because sourceNavigationController     and destination were equal     Optional(<SwiftUI.UIKitNavigationController: 0x14c18200>)
[NavigationHostingControllerCache_UIKit] <_TtGC7SwiftUI32NavigationStackHostingControllerVS_7AnyView_: 0x15424400> containment skipped because sourceNavigationController or destination were nil
[NavigationHostingControllerCache_UIKit] <_TtGC7SwiftUI32NavigationStackHostingControllerVS_7AnyView_: 0x15432800> containment skipped because sourceNavigationController or destination were nil

代码:

import SwiftUI

@main
struct WearableBankingApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView1()
        }
    }
}

struct ContentView1: View {
        
    @State var path = NavigationPath(["1", "2"])
    
    var body: some View {
        NavigationStack(path: $path) {
            
            VStack {
                NavigationLink("Go to int screen", value: "1")
                 
            }
            .navigationDestination(for: String.self) { value in
                Text("This is a string screen with value: \(value)")
            }
        }
    }
}
ios swift swiftui swiftui-navigationstack
1个回答
0
投票

看起来下面的代码可能更符合您的要求?

struct ContentView1: View {
    
    var destinations = ["1", "2"]
    @State var path = NavigationPath()
    
    var body: some View {
        NavigationStack(path: $path) {
            VStack {
                ForEach(destinations) { value in
                    NavigationLink("Go to int screen", value: value)
                }
            }
            .navigationDestination(for: String.self) { value in
                Text("This is a string screen with value: \(value)")
            }
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.