UIPageViewController作为应用程序的根控制器

idS*_*tar 2 objective-c ios5 uipageviewcontroller

我是UIPageViewController第一次使用.当然,iOS5和我对ARC很满意.我没有使用Storyboard.

在我看到的所有零碎的例子中,UIPageViewController从不"拥有"屏幕.它始终是其他视图控制器的子项.这是一个要求吗?我想让它成为我的应用程序的根控制器,就像通常所做的那样UINavigationController.我试图以编程方式设置它,但我得到的只是一个空的页面视图控制器,其中没有内容.

以下是应用程序的启动方式(这里的所有代码都在我的app委托类中):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    [self configureLoggers];
    [self applyAppearanceProxySettings];
    [self configureDataStore];
    [self configureNavigationController];
    [self configurePageController];    // <-- this is where we do the page view controller setup, shown next.

    self.window.rootViewController = self.pageController;
    [self.window makeKeyAndVisible];

    log4Info(@"Application completed launching.");

    return YES;
}
Run Code Online (Sandbox Code Playgroud)

在上面的代码中提到的那个方法,它为页面视图控制器进行了设置:

- (void)configurePageController {
    CCFrontCoverViewController *frontCoverViewController = [[CCFrontCoverViewController alloc] initWithNibName:nil bundle:nil];

    NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:UIPageViewControllerSpineLocationMin]
                                                    forKey:UIPageViewControllerOptionSpineLocationKey];

    self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
                                                      navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
                                                                    options:options];

    self.pageController.delegate = self;
    self.pageController.dataSource = self;
    self.pageController.view.backgroundColor = [UIColor redColor]; // So we know we're missing content because red shows through.

    NSArray *pageViewControllers = [NSArray arrayWithObjects:frontCoverViewController, self.navigationController, nil];
    [self.pageController setViewControllers:pageViewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
}
Run Code Online (Sandbox Code Playgroud)

我还记录了两个数据源回调方法,它们甚至都没有被调用.

当这个运行时,我只是得到一个空白的红色屏幕.同样,没有涉及故事板.我错过了什么?

Tim*_*tis 5

我可以UIPageViewController在示例项目中使用a 作为根视图控制器,前提是:

  • UIPageViewController与一个有效的脊骨位置正确初始化.
  • UIPageViewControllerdoubleSided属性设置(与脊骨位置一致).
  • 所述UIPageViewControllerviewControllers阵列被设置(再次,与脊柱位置和一致的doubleSided属性).

它看起来像您还没有设置doubleSidedYES在你的代码(因为你的viewControllers阵列,它有两个项目).在设置viewControllers阵列之前添加它可以解决您的问题吗?

编辑:仅供后人使用,在UIPageViewController文档中,setViewControllers:direction:animation:completion:方法说明中有一个图表,显示了所有有效脊柱位置组合的视图控制器数量doubleSided.