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.'
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.