2
votes

I am developing an application and I am using iOS5 storyboard. Basically what I have is a UITabBarController as the root controller which contains some UIViewController and a UISplitViewController. What I want to do is to use a UIPageViewController as the DetailController of the UISplitViewController. The problem is that the UIPageViewController doesn't show its view controllers but it shows a black screen. What I do is to initialize two content view controllers in the viewDidLoad method of the DetailController and assign them with the instruction:

[self setViewControllers:self.pagesViewControllerArray direction:UIPageViewControllerNavigationOrientationHorizontal animated:NO completion:nil];

so I cannot figure out where is the mistake.

The viewDidLoad method is the following:

- (void)viewDidLoad{

    self.dataSource = self;
    self.delegate = self;

    self.page1ViewController = [[Page1ViewController alloc] initWithNibName:@"Page1ViewController" bundle:nil];
    self.page2ViewController = [[Page2ViewController alloc] init];

    self.pagesViewControllerArray = [NSArray arrayWithObjects:self.page1ViewController, self.page2ViewController, nil];

    [self setViewControllers:self.pagesViewControllerArray direction:UIPageViewControllerNavigationOrientationHorizontal animated:NO completion:nil];

} 

I tried to use both a viewcontroller with its nib associated and a viewcontroller with its view dynamically loaded but it is not working.

Any help would be really appreciated. Thanks

1

1 Answers

0
votes

First make sure viewDidLoad is being called. There are so many ways an instance may be initialized and I am not sure when each option is used. If initWithNibName is used then viewDidLoad will not be called, if I remember correctly. To make sure the method is called you can add an NSLog statement like...

NSLog(@"viewDidLoad: %@", NSStringFromClass([self class]));

That will show in the debugger console if it is being called. You can also add the initWithNibName method to see if that is called.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        NSLog(@"initWithNibName: %@", NSStringFromClass([self class]));
    }
    return self;
}

I have found that Storyboards do not work as I expected. What I have started using is Container Views. There is nothing fancy about them. They are just visual elements you can place inside of a view which are then wrappers around a standard UIViewController and then the design surface shows the related view with the same dimensions as the container view you placed in the other view. Then you can manage the details there. If you do need to handle any initialization with the parent view controller you will use the prepareForSegue method. You will need to set the name for the embed segue for the container view (not a push segue like you usually see) and when it fires you can access the destinationViewController which is simply the embedded view controller inside of the container view. It may take some tinkering to figure it out.

Also look up UIPageViewController in the Documentation tab of the Organizer. There is a sample project listed at the bottom of the left column which you may find useful.