iOS crash with UIMoreNavigationController

I am getting a crash in my iOS Storyboard app which is easily reproducible.

When I enable Zombie Objects, this is the crash message I get.

2023-08-09 21:25:30.736022+1000 ThingyTwo[31860:4546795] *** -[UITabBarController removeChildViewController:]: message sent to deallocated instance 0x14b830000
(lldb) 

It happens when:

  1. A UITabBarController is placed within a UINavigationController.
  2. The UITabBarController has more than 5 view controllers, which then internally uses a UIMoreNavigationController to display the remainder.
  3. The UINavigationController is removed from the view hierarchy.

It doesn't crash 100% of the time, usually somewhere between 20% and 80%.

I have created a bare-bones implementation almost entirely as a storyboard.

https://github.com/adamroyle/more-controller-crash

Run the project, click the "Show" button, and then click the "Dismiss" button. Keep repeating this until it crashes, it shouldn't take long.

Please let me know if you know of any simple workaround to this?

Thanks for bringing this issue to our attention. This appears to be a bug, we'll investigate further.

In my actual app the UINavigationController is the rootViewController, and it crashes when the user kills the application (using swipe up gesture).

I tried a bunch of things, but the following code ended up fixing the issue for me.

class NavigationController: UINavigationController {
    override func viewWillDisappear(_ animated: Bool) {
        if !animated {
            setViewControllers([], animated: false)
        }
        
        super.viewWillDisappear(animated)
    }
}
iOS crash with UIMoreNavigationController
 
 
Q