5

下面的代码在 WatchOS 7 和 8.0 中运行良好,但现在在 8.1 中,点击该行将导航到目的地,然后立即导航回根视图。

我提交了反馈 #FB9727188 并包含以下内容以演示该问题。

struct ContentView: View {

 @State var tabIndex:Int = 0

    var body: some View {
            TabView(selection: $tabIndex) {
            ListView()
                .tabItem { Group{
                    Text("List")
                }}.tag(0)
                .padding(.bottom, 1.0)
             Text("Second View")
                .tabItem { Group{
                    Text("Second")
                }}.tag(1)
            .padding(.bottom, 1.0)
             Text("Third View")
                .tabItem { Group{
                    Text("ThirdView")
                }}.tag(2)
           
        
            
        }
    }
}


struct ListView: View {
    var body: some View {
         List {
            ForEach((1...10).reversed(), id: \.self) {_ in
                NavigationLink(destination: Text("test")) {
                    Text("Tap Me but we'll just be back here")
                }
            }
            
        }
    }
}
4

1 回答 1

1

watchOS 8.1(和 8.3 beta)在使用以前的 watchOS 版本时遇到了同样的问题。

我们可以通过NavigationView移动TabView. 这种解决方法根本不理想,但似乎确实有效。

@State private var tabSelection = 1

var body: some Scene {
    WindowGroup {
        TabView(selection: $tabSelection) {
            NavigationView {
                // List goes here
            }
            .tag(1)
            
            VStack {
                // content 2nd tab: we didn't have a list in the 2nd tab
            }
            .tag(2)
        }
    }
}

但是,此修复会影响两件事:

  • 我没有得到navigationBarTitle工作,所以屏幕顶部不会有标题。
  • 如果您单击列表中的某个项目,它将导航到您的页面(如预期的那样),但屏幕底部的 TabView 点将保留。
于 2021-11-12T10:42:12.143 回答