objective-c - UIPageViewController 作为应用程序的根 Controller

标签 objective-c ios5 uipageviewcontroller

我是第一次使用UIPageViewController。当然是iOS5,而且我对ARC很满意。我使用 Storyboard。

在我看到的所有零散示例中,UIPageViewController 从未“拥有”屏幕。它始终是其他 View Controller 的子级。这是一个要求吗?我想让它成为我的应用程序的根 Controller ,就像通常使用 UINavigationController 所做的那样。我试图以编程方式将其全部设置,但我得到的只是一个空的页面 View Controller ,其中没有任何内容。

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

- (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;
}

上面代码中提到的方法,用于设置页面 View Controller :

- (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];
}

我还在两个数据源回调方法中添加了日志记录,但它们甚至没有被调用。

当它运行时,我只是看到一个空白的红色屏幕。再说一次,没有涉及 Storyboard。我错过了什么?

最佳答案

我可以使用 UIPageViewController 作为示例项目中的 Root View Controller ,前提是:

  • UIPageViewController 已使用有效的书脊位置正确初始化。
  • UIPageViewControllerdoubleSided 属性已设置(与书脊位置一致)。
  • UIPageViewControllerviewControllers 数组已设置(再次与书脊位置和 doubleSided 属性一致)。

看起来您尚未在代码中将 doubleSided 设置为 YES (因为您的 viewControllers 数组中有两个项目)。在设置 viewControllers 数组之前添加该内容是否可以解决您的问题?

编辑:仅供后代使用,在UIPageViewController docssetViewControllers:direction:animation:completion: 方法的描述中有一个图表,显示了脊柱位置和 doubleSided 的所有有效组合所允许的 View Controller 数量。

关于objective-c - UIPageViewController 作为应用程序的根 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8839670/

相关文章:

iphone - 模拟 iPhone 的低电量

ios - 在PageViewController中显示模态ViewController

swift - UIPageViewControllerDelegate : 'NSInternalInconsistencyException' , 原因: 'Invalid parameter not satisfying: [views count] == 3'

iphone - 在我的对象类中使用 typedef 枚举

iphone - 在 iPhone 中解析带有用户名和密码的 url

iphone - 使用selector方法调用C Function并在iPhone的c方法中访问self

xcode - iOS : NSXMLParser get attribute

c++ - 如何在 ios 平台上使用 c++ 实现 GameCenter

ios - UIPageViewController 旋转怪异

ios - 如何以编程方式在 google map 中移动一个点 xcode