我有一个以UINavigatonController
开头的故事板。 rootViewController
指向UIViewController
,其上有一个按钮。按钮将(推)到UIPageViewController
。
当UIPageViewController
加载时,我以编程方式创建页面视图(由xib文件中的另一个视图控制器定义)。
当我运行应用程序时,单击按钮会按预期转换,但生成的视图始终为空(仅黑屏)。似乎我错过了一些非常明显的东西,但几天后我寻求帮助!
以下是UIPageViewController
- (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;
}