Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSInternalInconsistencyException from UIPageViewController when rotating

I'm on Monotouch 5.2.6 and iOS SDK 5.0.1.

I have a UIPageViewController that is a child container of another view controller. It is created like this:

pageViewController = new UIPageViewController (UIPageViewControllerTransitionStyle.PageCurl, UIPageViewControllerNavigationOrientation.Horizontal, UIPageViewControllerSpineLocation.Min);
    this.AddChildViewController (pageViewController);
    pageViewController.DidMoveToParentViewController (this);
    this.viewCurrentMode.AddSubview (pageViewController.View);

If I rotate the device (Simulator), I get this exception in UIApplication.SendEvent():

Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: The number of provided view controllers (1) doesn't match the number required (2) for the requested spine location (UIPageViewControllerSpineLocationMid)

The spine location is NOT "mid" but "min". Any ideas?

like image 604
Krumelur Avatar asked Oct 09 '22 09:10

Krumelur


1 Answers

True, you have initialized the UIPageViewController with "Min" as spine location. However, you need to implement a delegate for your page controller and override the GetSpineLocation method:

public override UIPageViewControllerSpineLocation GetSpineLocation (UIPageViewController pageViewController, UIInterfaceOrientation orientation)
{

    //return spine location according to interface orientation and whatever
    //criteria you prefer

}

Or, assign a method to its GetSpineLocation property (MonoTouch heaven! ):

pageViewController.GetSpineLocation = (p, o) => return <spinelocation>;

Still, it looks a bit unexpected behavior. I assume that the default implementation of the native pageViewController:spineLocationForInterfaceOrientation: method returns "Mid" when the device rotates to landscape (although could not find info in Apple docs). Anyway, you must override the above method to get it right.

like image 163
Dimitris Tavlikos Avatar answered Oct 12 '22 00:10

Dimitris Tavlikos