xcodexcode15ios17

'NSInternalInconsistencyException', reason: 'Layout requested for visible navigation bar Xcode 15.0 Crash


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


Solution

  • For us, we've also experienced the same crash when the app is compiled using Xcode 15.0.1 and running on iOS 17 (work fine with Xcode 14.x). Our app moves view controllers from one navigation controller to another navigation controller using the following code:

    self.navigationController?.viewControllers = oldNavigationController.viewControllers
    oldNavigationController.dismiss(animated: false, completion: nil)
    

    The crash is immediately gone after we've inserted the following line of code before dismissing the oldNavigationController:

    oldNavigationController.viewControllers = [UIViewController]()