导航视图后退按钮不显示

Cod*_*ddy 2 swiftui swiftui-navigationview

有一个简单的 NavigationView,两侧都有固定的内容。左窗格仅显示几个按钮,右窗格显示使用 NSViewRepresentable 包装的 NSView 的图形。在 iPad 上以纵向模式查看时,左窗格会按预期消失,但不会显示“后退”按钮。可以单击预期“后退”按钮的区域,然后显示左窗格。那里什么也看不见。

我究竟做错了什么?

  var body: some View {
    NavigationView {
        VStack(alignment: .center) {
            Text("This is the left side")
            Button {
                ...
            } label: {
                Text("Create Estimate")
            }.foregroundColor(Color.black)
            Button {
                ...
            } label: {
                Text("Reset Results")
            }.foregroundColor(Color.black)
            Text("This is the end of the left side")
        }
        VStack {
            Text("This is the right side")
            AreaChartView(redrawCount: redrawCounter, scenario: activeScenario)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

}

更新:即使我注释掉上面导航视图中的所有内容并替换为:也会发生这种情况

   NavigationView {
        Text("This is the left side")
        Text("This is the right side")
        }
Run Code Online (Sandbox Code Playgroud)

请注意,我创建了一个新的 iOS 项目,除了这个超级简单的 NavigationView 之外什么都没有,它按预期显示了“后退”按钮。由于实际上除了上面的 NavigationView 之外,我的应用程序视图中的所有内容都被注释掉了,我想知道环境中还有什么问题。请注意,我的应用程序是一个多平台应用程序,而不仅仅是 iOS,尽管我不知道为什么这很重要。

Cod*_*ddy 8

好吧 - 对于任何其他可能遇到这种情况的可怜的灵魂......

当我发现即使是一个简单的 NavigationView 也没有“后退”按钮(参见问题)时,很明显问题根本不在视图代码中。进行了一些搜索,但发现资源文件中的默认强调色已更改为白色。这意味着“后退”按钮在白色背景下呈白色,因此是不可见的。

删除这些白色强调色会导致 SwiftUI 使用默认值。现在“返回”按钮按预期显示为蓝色。