Search code examples
iosxcodeuinavigationcontrolleruistoryboarduisplitviewcontroller

UISplitViewController: Crash on rotating on iPhone 6 Plus


I have a problem using an UISplitViewController on iOS 8.

Specifically it crashes when rotating the screen, and this only occurs on the iPhone 6 Plus. I assume it happens when the controller tries to split/merge the view controllers.

My navigation stack can be a bit complex, both the left and right sides of the split view have a UINavigationController. And several items can be pushed on the left stack before switching to the right stack. It's really quite similar to the default mail app. Where you choose your mailbox, open folders and browse the mail list on the left stack, and show mail and open attachments and such on the right stack.

I was able to configure and connect how the different views behave using nothing but storyboard configuration by using Show (e.g. Push) to push on the left stack and Show Detail (e.g. Replace).

After clicking around (and filling the right stack), rotating on the iphone 6 plus will crash the app. I realised it happens because this is the only device expanding and collapsing the two sides onto each other. There's no real info given by the debugger, only thing I sometimes get is:

-[UIView updateNavigationBarButtonsAnimated:]: unrecognized selector sent to instance

Note where it says UIView, this seems to be random (NFCString, NSArray, etc), so I figured it's unexpectedly nil and points to the random code on the heap.

I also realise this has something to do with the UISplitViewControllerDelegate methods, but I just cannot figure out what I should really do to make it work.


Solution

  • I had the same issue.
    My crash was caused by setting the leftBarButtonItem in viewDidLoad in a subclass of UISplitViewController. I deleted these two lines of code.

    let navigationController = self.viewControllers[self.viewControllers.count-1] as! UINavigationController
    navigationController.topViewController.navigationItem.leftBarButtonItem = displayModeButtonItem()
    

    Now I set the leftBarButtonItem in prepareForSegue. That´s the way Apple does it in the Master/Detail example ;-)