I update my Xcode to 15.0 and run application. When run application on iOS 17 my app is crashing with this Error:
Assertion failure in -[UINavigationBar layoutSubviews], UINavigationBar.m:3 849 ‘NSInternalInconsistencyException’, reason: ‘Layout requested for visible navigation bar
It happens only on iOS 17 with Xcode 15.0. With Xcode 14.3 and iOS 17 – no. With Xcode 15 and iOS 16.4 – no.
*** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Layout requested for visible navigation bar, <UINavigationBar: 0x15bd34ee0; frame = (0 47; 428 44); autoresize = W; tintColor = UIExtendedGrayColorSpace 0 1; layer = <CALayer: 0x2813b9f40>> delegate=0x15c049e00 standardAppearance=0x2837b03c0 scrollEdgeAppearance=0x2837b02a0 compactAppearance=0x2837b0540 compactScrollEdgeAppearance=0x2837b0240, when the top item belongs to a different navigation bar. topItem = <UINavigationItem: 0x15bf26070> titleView=0x160f04840 style=navigator backBarButtonItem=0x15bf5f4d0 rightBarButtonItems=0x281c93f90, navigation bar = <UINavigationBar: 0x15bd05d60; frame = (0 47; 428 44); autoresize = W; tintColor = UIExtendedGrayColorSpace 0 1; layer = <CALayer: 0x2813be380>> delegate=0x15c056800 standardAppearance=0x2837fd5c0 scrollEdgeAppearance=0x2837fd7a0 compactAppearance=0x2837fd080 compactScrollEdgeAppearance=0x2837ff780, possibly from a client attempt to nest wrapped navigation controllers.’
Need help 🙂
I already set navigationController?.setNavigationBarHidden(true, animated: false)
in viewWillLayoutSubviews()
but it’s not helped
2
Answers
After I removed/commented this line, the crash has gone.
YOU NEED TO REMOVE/COMMENT ONLY
viewWillLayoutSubviews
but this didn't helpsetNeedsLayout()
andlayoutIfNeeded()
but this alsodidn't help
I had the same issue, and the reason was in
UISplitViewController
‘s delegate: insplitViewController(_:collapseSecondary:onto:)
when I moved the view controllers from a secondary navigation controller to the primary one I didn’t remove them from the secondary navigation controller. After I started to remove them, the crash has gone. So try to check the places where you change the view controllers’ parents.