在UINavigationController中使用UIPageViewController时,页面始终为空

时间:2013-01-19 01:32:37

标签: uinavigationcontroller uipageviewcontroller

我有一个以UINavigatonController开头的故事板。 rootViewController指向UIViewController,其上有一个按钮。按钮将(推)到UIPageViewController

UIPageViewController加载时,我以编程方式创建页面视图(由xib文件中的另一个视图控制器定义)。

当我运行应用程序时,单击按钮会按预期转换,但生成的视图始终为空(仅黑屏)。似乎我错过了一些非常明显的东西,但几天后我寻求帮助!

以下是UIPageViewController

的viewDidLoad代码
- (void)viewDidLoad
{    
    [super viewDidLoad];

    //Create the content
    [self createContentPages];

    //Set the initial view controllers.

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

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

    pageController.dataSource = self;

    ContentViewController *contentViewController = [[ContentViewController alloc] initWithNibName:@"ContentViewController" bundle:nil];
    contentViewController.dataObject = [self.pageContent objectAtIndex:0];
    NSArray *viewControllers = [NSArray arrayWithObject:contentViewController];

    [self.pageController setViewControllers:viewControllers 
                                  direction:UIPageViewControllerNavigationDirectionForward
                                   animated:NO 
                                 completion:nil];

    [self addChildViewController:self.pageController];
    [self.view addSubview:self.pageController.view];
    [self.pageController didMoveToParentViewController:self];    

    //Assign the gestureRecognizers property of our pageViewController to our view's  gestureRecognizers property.
    self.view.gestureRecognizers = self.pageController.gestureRecognizers;
}

0 个答案:

没有答案