UIPageViewController doesn't work at all; totally blank
-
05-12-2019 - |
Question
So,
I'm trying to use the UIPageViewController
with a custom application workflow, but I'm implementing it exactly as recommended in the docs.
self.pageViewController = [[[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil] autorelease];
//calls setViewControllers:direction:animated:completion with valid UIViewControllers
[self setupPagesWithIndex:0];
self.pageViewController.delegate = self;
self.pageViewController.dataSource = self;
self.view.frame = CGRectMake(0, 0, 1024, 768);
self.pageViewController.view.backgroundColor = [UIColor grayColor];
Here is where I set the view controllers...
- (void) setupPagesWithIndex:(NSInteger) index
{
UIViewController* vc1 = [self uicontrollerForIndex:index];
UIViewController* vc2 = [self uicontrollerForIndex:index+1];
[self.pageViewController setViewControllers:[NSArray arrayWithObjects:vc1,vc2, nil]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
}
The only thing that appears on screen is the grey background color. I have verified that the UIViewControllers
are valid, have good frames and I even gave them background colors just so I could see something
This is how I'm adding the UIPageViewController to the screen:
[[self rootViewController] addChildViewController:self.pageViewController];
[[self rootViewController].view addSubview:self.pageViewController.view];
[self rootViewController]
returns the application's rootViewController.
The view is definitely visible, because I can see the backgroundcolor I apply... however, the UIPageViewController is just totally blank!
I implemented all of the datasource and delegate methods and adopted the protocols; they never even get called!
My question is; what are all of the requirements for the UIPageViewController to display pages when you do everything programmatically?
edit #1, per request: This class is a controller for UIPageViewController within my own application-building framework. I'm giving the controller two ways of building a page right now -- from an image name or from a kind of asset key. In either case, it ultimately returns a view which I wrap with a UIViewController.
I create the view controller with
UIViewController* vc = [[[PageTest alloc] initWithNibName:@"PageTest" bundle:nil] autorelease];
'PageTest' is just a UIViewController with a corresponding nib, which is blank except for the auto-generated settings. I then add my custom view as a subview to this view controller. This is what comes back from uicontrollerForIndex:
edit #2, further discovery
I've found a way to show the book flipper; if I only initialize it with one view controller it will show the book flipper. It doesn't matter if the two view controllers are different classes entirely; if I setViewControllers with two of them then nothing shows.
if I return UIPageViewControllerSpineLocationMid
in the delegate method
- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation
Then upon rotation, the app will crash without an identifiable backtrace.
Solution
With the,
- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation
method, you must call setViewControllers
before returning the spineLocation
.