app crash on iOS 16.1(beta) when using "self.navigationController.navigationBarHidden = NO"

My app was built with XCode13 and we are now seeing occasional crashes on iOS16.1 (beta). This exception occurs when using the method:

self.navigationController.navigationBar.hidden = NO

The following is the exception information:

Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to activate constraint with anchors <NSLayoutDimension:0x28130fd00 "_UINavigationBarTitleControl:0x112523b40.height"> and <NSLayoutDimension:0x281308340 "UILayoutGuide:0x283f97100'TitleViewGuide(0x112619390)'.height"> because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.'

Can you post the version of the iOS 16.1beta you are running? (it should be something like 20A50(2 digit number)(letter))

The full crash stack:

I have the same problem. The version of the iOS 16.1 is 20B5045d.

Have same error. And setting:

navigationItem.titleView = UIView() works for me

Looks like there is a title/view required in new navigationView stack implementation

Accepted Answer

if (@available(iOS 16.1, *)) {

    [self.navigationBar setNeedsLayout];

    [self.navigationBar layoutIfNeeded];

  }

It can fix this problem. I found it's Apple's bug because the new Navigation Title in iOS 16 is TitleControl Class.

When you compile and run Xcode 13, it has a delay in updating constraints, It cause LayoutGuide's sosConstrain release(unsafe_unretained), So it caused a crash。

You can call the above two lines of code to let the navigation update the constraint layout of TitleControl immediately.

app crash on iOS 16.1(beta) when using "self.navigationController.navigationBarHidden = NO"
 
 
Q