SwiftUI navigationBarTitle 导致控制台警告

Rex*_*xha 5 xcode ios swift swift5 swiftui

我试图隐藏后退按钮名称,解决方案是这两行:

.navigationBarHidden(true)
.navigationBarTitle("")
Run Code Online (Sandbox Code Playgroud)

一切工作正常,除了这个长控制台警告,这使得调试非常困难,因为我需要滚动或过滤很多才能看到所需的输出。

这条线导致了它:.navigationBarTitle("")

任何想法如何解决这一问题?

警告:

    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:0x600003823de0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x11fe70c30]-(6)-[_UIModernBarButton:0x11fe6f370' ']   (active)>",
    "<NSLayoutConstraint:0x600003823e30 'CB_Trailing_Trailing' _UIModernBarButton:0x11fe6f370' '.trailing <= _UIButtonBarButton:0x11fe6eda0.trailing   (active)>",
    "<NSLayoutConstraint:0x600003850aa0 'UINav_static_button_horiz_position' _UIModernBarButton:0x11fe70c30.leading == UILayoutGuide:0x600002251500'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x600003850af0 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x11fe6eda0]-(0)-[UILayoutGuide:0x600002251420'UINavigationBarItemContentLayoutGuide']   (active)>",
    "<NSLayoutConstraint:0x60000383b7a0 'UINavItemContentGuide-trailing' UILayoutGuide:0x600002251420'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x11fe58990.trailing   (active)>",
    "<NSLayoutConstraint:0x600003851270 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x11fe58990.width == 0   (active)>",
    "<NSLayoutConstraint:0x60000383bb60 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x600002251500'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UINavigationBarContentView:0x11fe58990 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600003823de0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x11fe70c30]-(6)-[_UIModernBarButton:0x11fe6f370' ']   (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.
Run Code Online (Sandbox Code Playgroud)

看法:

struct HomeView: View {
    var body: some View {
        NavigationView {
            VStack {
                //
            }
            .navigationBarHidden(true)
            .navigationBarTitle("") // Probably at least one of the constraints in the following list is one you don't want.
        }
        
    }
}

struct TabViewContainerView: View {
    
    var body: some View {
        TabView {
            HomeView()
                .tabItem {
                    Image(systemName: "house.fill")
            }
            .tag(0)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)