旋转时来自UIPageViewController的NSInternalInconsistencyException

Kru*_*lur 5 c# cocoa-touch xamarin.ios ios uipageviewcontroller

我在使用Monotouch 5.2.6和iOS SDK 5.0.1.

我有一个UIPageViewController,它是另一个视图控制器的子容器.它是这样创建的:

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

如果我旋转设备(模拟器),我会得到以下异常UIApplication.SendEvent():

抛出Objective-C异常.名称:NSInternalInconsistencyException原因:提供的视图控制器(1)的数量与请求的脊椎位置所需的数量(2)不匹配(UIPageViewControllerSpineLocationMid)

脊柱位置不是"中间"而是"最小".有任何想法吗?

Dim*_*kos 4

确实,您已经使用“Min”作为书脊位置初始化了 UIPageViewController。但是,您需要为页面控制器实现委托并重写该GetSpineLocation方法:

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

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

}
Run Code Online (Sandbox Code Playgroud)

或者,为其GetSpineLocation属性分配一个方法(MonoTouch 天堂!):

pageViewController.GetSpineLocation = (p, o) => return <spinelocation>;
Run Code Online (Sandbox Code Playgroud)

不过,这看起来有点出乎意料。我假设当pageViewController:spineLocationForInterfaceOrientation:设备旋转到横向时,本机方法的默认实现返回“Mid”(尽管在 Apple 文档中找不到信息)。不管怎样,你必须重写上面的方法才能得到正确的结果。