3

我有以下系列的控制器和视图。但是,当我在 MoreView 上使用导航链接时,它会更改 tabBarItem.title 的值。例如,它会说更多,但是当单击隐私策略按钮并将用户导航到策略视图时,标签栏中的标题将更改为 .navigationBarTitle() 中的任何内容,或者如果未提供,则为空字符串!我该如何避免这种情况?我希望标签栏标题是静态的

UITabBar -> UINavigationController -> MoreViewController(UIHostingController) -> MoreView(SwiftUI)

更多查看

List {
            
            Section(
                header: Text("ABOUT"),
                footer: Text(aboutFooter)
                        .font(.caption)
                ) {
                    NavigationLink(destination: WebView(
                        request: URLRequest(url: URL(string: "https://www.websitepolicies.com/policies/view/ng0sNvAJ")!)
                        )//.navigationBarTitle(Text("Privacy Policy"))
                    ) {
                        Text("Privacy Policy")
                    }
                    Text("Attribution")
            }
        }
        .listStyle(GroupedListStyle())
        .environment(\.horizontalSizeClass, .regular)
4

1 回答 1

5

这是iOS中的一个错误。请向 Apple 提交错误报告。

我刚刚发现了解决此问题的方法

创建一个自定义子类UINavigationController并将其用作包含您的MoreViewController.

class WorkaroundUINavigationController: UINavigationController {
    override var title: String? {
       get { tabBarItem.title }
       set { navigationItem.title = newValue }
    }
}
于 2020-07-05T08:52:33.160 回答