8

We use Firebase's Crashlytics and in the last 2 days we've seen a spike in crashes with navigationController?.setNavigationBarHidden on iOS 16 devices. I was able to reproduce the crash after installing Xcode 14.5

I have a view controller (VC1) embedded in a navigational controller with the following code in

override func viewWillDisappear(_ animated: Bool) {
  super.viewWillDisappear(animated)
  ...
  navigationController?.setNavigationBarHidden(false, animated: animated) // crash here
}

and after I push another view controller (VC2) using the following code

navigationController?.pushViewController(vc, animated: true)

the app crashes with the following error message

2022-08-10 15:07:04.866752-0700 autolist-dev[22341:3295980] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to activate constraint with anchors <NSLayoutXAxisAnchor:0x600001a9d740 "_UITAMICAdaptorView:0x7fd6c70ddbe0.leading"> and <NSLayoutXAxisAnchor:0x600001466680 "_UINavigationBarTitleControl:0x7fd6c70dcb80.leading"> because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.'

It doesn't immediately crash the first time VC2 is pushed. After I go back to VC1 and then push VC2 again then the app crashes.

Does anyone have any ideas on how to resolve this? I can't seem to find anyone else having a similar issue

josealvarado111
  • 565
  • 1
  • 9
  • 24
  • I had a flavour of this issue where navigation bar is hidden but still takes up space and gives choppy animation. Did you find a fix @josealvarado111 – Ali Sep 01 '22 at 20:26
  • hi @josealvarado11, we are facing the same issue now that iOS 16 has been publicly released, although it doesn't happen to all the users. We're still working on it but we're trying to avoid to call setNavigationBarHidden inside viewWillDisappear and instead we're using navigation controller delegates (viewControllerWillShow and viewControllerDidShow). Did you manage to fix it? If so, how? Thanks – pAkY88 Sep 17 '22 at 06:25
  • 2
    @pAkY88 The issue for us ended up being a constraint issue that was added to a custom NavigationBar. For some reason setting it to hidden was asking the constraints to be reset. The culprit was using UILabel's sizeToFit() function. We removed this and programmatically set the constraints and that fixed the issue. Good luck! – josealvarado111 Sep 18 '22 at 15:45
  • @josealvarado111 You should put that as an answer, I would really like to upvote it. That saved me hours of searching. – Sulthan Sep 19 '22 at 18:04
  • 1
    @josealvarado111 Check this, works for me https://developer.apple.com/forums/thread/714679 – boog Sep 20 '22 at 10:35
  • @boog thank you very much, I was going crazy trying to figure out where the problem was, good to know it's an iOS bug that will be fixed soon by Apple. – pAkY88 Sep 20 '22 at 14:14

0 Answers0