UISplitViewController: Crash When Rotating On iPhone 6 Plus

I have a problem using UISplitViewController on iOS 8.

In particular, it crashes when you rotate the screen, and this only happens on the iPhone 6 Plus. I guess this happens when the controller tries to split / merge the view controllers.

My navigation stack can be a little tricky, and the left and right sides of the split view have a UINavigationController. And multiple items can be pushed on the left stack before being pushed onto the right stack. It really looks a lot like the default mail app. Where do you select your inbox, open folders and view the list of emails in the stack on the left, and also show mail and open attachments, etc. On the right stack.

I was able to customize and wire the behavior of the different views using just the storyboard configuration using Show (e.g. Push)

to push to the left stack and Show Detail (e.g. Replace)

.

After clicking (and filling the desired stack), spinning on iphone 6 plus will crash the app. I realized this was happening because it is the only device that expands and folds both sides onto each other. There is no real information provided by the debugger, only I sometimes get:

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

Note where it says UIView

it seems to be random (NFCString, NSArray, etc.), so I suddenly figured it out and pointed to the random code on the heap.

I also understand that it has something to do with methods UISplitViewControllerDelegate

, but I just can't figure out what I should be doing to get it to work.

+3


source to share


2 answers


I had the same problem.
My crash was caused by setting leftBarButtonItem to viewDidLoad in a UISplitViewController subclass. I removed these two lines of code.

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

      



Now I am setting leftBarButtonItem to prepareForSegue. This is how Apple does it in the Master / Detail example ;-)

+1


source


"I also understand that it has something to do with the UISplitViewControllerDelegate methods, but I just can't figure out what I should be doing to get it to work."

You're right. I have the same problem and fix this:

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    if (self.isMovingFromParentViewController) {
        // To avoid deallocated problem with SplitVC delegates
        self.splitViewController.delegate = nil;
        // Do your stuff here
    }
}

      



In other words, you must assign nil to the splitViewController delegate when the screen disappears.

Hope this helps you like me.

0


source







All Articles