Search code examples
iosipaduisplitviewcontrolleruipopovercontroller

SplitViewController crashing in Portrait view (ipad)


I have a tabbed application that contains five splitviewcontrollers.

In portrait mode, the 'master' button appears as expected, and on the first two controllers that button behaves as expected. On the last three tabs however, the button causes a crash with the following message:

Assertion failure in -[_UISlidingPopoverLayoutInfo _popoverViewSizeForContentSize:arrowDirection:], /SourceCache/UIKit_Sim/UIKit-1914.84/_UIPopoverLayoutInfo.m:160 2012-04-24 19:15:38.674 SMToolkit[12420:11303] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unknown direction passed to _popoverViewSizeForContentSize:arrowDirection:'

Thing is, the five views are cut-n-pasted from the same source, pretty much Apple's boilerplate. I'm not actually storyboarding the popovers, nor do I have them in a prepareforsegue method, since the spliltviewcontroller theoretically gives them to me 'for free'

All five splitviewcontrollers conform to UISplitViewControllerDelegate

The appdelgate is like so:

    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
   //Person
    UISplitViewController *personSplitViewController = [tabBarController.viewControllers objectAtIndex:1];
    UINavigationController *personNavigationController = [personSplitViewController.viewControllers lastObject];
    personSplitViewController.delegate = (id)personNavigationController.topViewController;
    UINavigationController *personMasterNavigationController = [personSplitViewController.viewControllers objectAtIndex:0];
    PersonMasterViewController *personController = (PersonMasterViewController *)personMasterNavigationController.topViewController;
    personController.managedObjectContext = self.managedObjectContext;
    //Scene
    UISplitViewController *sceneSplitViewController = [tabBarController.viewControllers objectAtIndex:2];
    UINavigationController *sceneNavigationController = [sceneSplitViewController.viewControllers lastObject];
    sceneSplitViewController.delegate = (id)sceneNavigationController.topViewController;
    UINavigationController *sceneMasterNavigationController = [sceneSplitViewController.viewControllers objectAtIndex:0];
    SceneMasterViewController *sceneController = (SceneMasterViewController *)sceneMasterNavigationController.topViewController;
    sceneController.managedObjectContext = self.managedObjectContext;

And so on, substituting the correct index in the tabBarController

Then in the detail view controllers, each has the following (identical, I checked):

- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
barButtonItem.title = NSLocalizedString(@"Master", @"Master");
[self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
self.masterPopoverController = popoverController;
}


- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
// Called when the view is shown again in the split view, invalidating the button and popover controller.
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
self.masterPopoverController = nil;
}

In the above, 'person' behaves as expected, but 'scene' causes the crash.

I don't see anywhere in any of the views anything that talks about what happens when that barbuttonitem is clicked, and it doesn't appear in the storyboard.

Ideas?


Solution

  • Unfortunately, in my case at least, the answer was that there was a pretty stupid bug in our code.

    What was happening was that in viewWillAppear for the master view we were setting some stuff on the detailview which was in turn trying to get the master view to appear. Taking that out and making each view control only itself solved the problem.