user1120133
user1120133

Reputation: 3234

Display Pageviewcontroller using storyboard segue

I have pageviewcontroller which i want to display and in this project using storyboard and segue

NSString *path = [[NSBundle mainBundle] pathForResource:@"Paper" ofType:@"pdf"];
PageViewController *page = [[PageViewController alloc] initWithPDFAtPath:path];
//[self presentViewController:page animated:NO completion:NULL];

If i use this statement

//[self presentViewController:page animated:NO completion:NULL];

then it doesn't display navigation bar and backbarbuttonitem

and when i remove this statement

 //[self presentViewController:page animated:NO completion:NULL];

then it doesn't display pageviewcontroller using curl effect transition for turning page over only it displays navigation bar and backbarbuttonitem.

and when i replace this statement

//[self presentViewController:page animated:NO completion:NULL];

with this statement

[self.view addSubview:page.view];

then it displays pageviewcontroller but doesn't turn page over at all.

Please help.

Thanks a lot.

Upvotes: 1

Views: 628

Answers (1)

Bradford2000
Bradford2000

Reputation: 723

I think I see your issue. Since you have the segue set up in the storyboard, you don't have to call presentViewController. I think what you actually want to do in the prepareForSegue function:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue destinationViewController] isKindOfClass:[PageViewController class]]) {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"Paper" ofType:@"pdf"];
        PageViewController *page = (PageViewController *)[segue destinationViewController];
        [page initWithPDFAtPath:path];
    }
}

Also, if the push segue is not built into the storyboard, you should be able to use your current code with one modification:

NSString *path = [[NSBundle mainBundle] pathForResource:@"Paper" ofType:@"pdf"];
PageViewController *page = [[PageViewController alloc] initWithPDFAtPath:path];
[[self navigationController] pushViewController:page animated:YES];

Hope this helps.

Upvotes: 1

Related Questions