Swiftui NavigationBarTitle在TabView中导致错误

Swiftui NavigationBarTitle在TabView中导致错误,swiftui,Swiftui,我已经开始在控制台中收到一条错误消息,每当我在选项卡视图中嵌套NavigationView时,就会收到下面的错误消息。有解决办法吗 struct ContentView: View { var body: some View { TabView{ NavigationView{ Text("Hello, world!") .padding()

我已经开始在控制台中收到一条错误消息,每当我在选项卡视图中嵌套NavigationView时,就会收到下面的错误消息。有解决办法吗

struct ContentView: View {
    var body: some View {
        TabView{
            NavigationView{
                Text("Hello, world!")
            .padding()
                    .navigationBarTitle("Hello World")
            }
            .tag(0)
            .tabItem {
                Text("Main")
            }
        
            NavigationView{
                Text("Hello, world!")
                    .padding()
                }
            .tag(1)
            .tabItem {
                Text("Secondary")
            }
            
        }.edgesIgnoringSafeArea(.top)
        
        
    }
}
我的控制台显示以下错误:

    2021-03-26 14:14:59.294828-0600 Playground[39119:2828740] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x600001ae5fe0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x7fdded4274f0]-(6)-[_UIModernBarButton:0x7fdded428920'Hello World']   (active)>",
    "<NSLayoutConstraint:0x600001ae6030 'CB_Trailing_Trailing' _UIModernBarButton:0x7fdded428920'Hello World'.trailing <= _UIButtonBarButton:0x7fdded7079f0.trailing   (active)>",
    "<NSLayoutConstraint:0x600001ae0230 'UINav_static_button_horiz_position' _UIModernBarButton:0x7fdded4274f0.leading == UILayoutGuide:0x6000000df1e0'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x600001ae94f0 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x7fdded7079f0]-(0)-[UILayoutGuide:0x6000000df100'UINavigationBarItemContentLayoutGuide']   (active)>",
    "<NSLayoutConstraint:0x600001aee800 'UINavItemContentGuide-trailing' UILayoutGuide:0x6000000df100'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x7fdded4253a0.trailing   (active)>",
    "<NSLayoutConstraint:0x600001ae9cc0 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x7fdded4253a0.width == 0   (active)>",
    "<NSLayoutConstraint:0x600001aeebc0 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x6000000df1e0'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UINavigationBarContentView:0x7fdded4253a0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600001ae5fe0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x7fdded4274f0]-(6)-[_UIModernBarButton:0x7fdded428920'Hello World']   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2021-03-26 14:14:59.294828-0600游乐场[39119:2828740][布局约束]无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。
试试这个:
(1) 看看每一个约束,试着找出你不期望的;
(2) 找到添加了不需要的约束的代码,然后修复它。
(
"",

“我在这里找到了答案:

我需要添加.navigationViewStyle(StackNavigationViewStyle())

当我将代码更新为此时,错误消失了:

struct ContentView: View {
var body: some View {
    TabView{
        NavigationView{
            Text("Hello, world!")
        .padding()
                .navigationTitle("Hello World")
        }
        .navigationViewStyle(StackNavigationViewStyle())
        .tag(0)
        .tabItem {
            Text("Main")
        }
    
        NavigationView{
            Text("Hello, world!")
                .padding()
            }
        .tag(1)
        .tabItem {
            Text("Secondary")
        }
        
    }.edgesIgnoringSafeArea(.top)
    
    
}
}