PrepareforSegue not displaying destinationviewcont

2019-09-05 09:13发布

问题:

Segue destinationviewcontroller pdfviewcontroller not displaying pageviewcontroller

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"MYSegue"]) {

    // Get destination view
    PDFViewController *pdfviewController = [segue destinationViewController];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"paper" ofType:@"pdf"];
    PageViewController *page = [[PageViewController alloc] initWithPDFAtPath:path];
    pdfviewController= page;

}
}

shows only navigation bar and backbuttonitem

and shows semantic issue incompatible pointer types assigning to pdfviewcontroller strong from pageviewcontroller strong.

Thanks for help.

回答1:

This line is wrong:

pdfviewController= page;

As the compiler tells you, the type is PDFViewController * and you're trying to assign PageViewController *.

Did you mean something like:

pdfviewController.page = page;

The segue should just do:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"MYSegue"]) {
        // Get destination view
        PDFViewController *pdfViewController = [segue destinationViewController];
        NSString *path = [[NSBundle mainBundle] pathForResource:@"paper" ofType:@"pdf"];

        pdfViewController.path = path;
    }
}

Add some properties to the pdf view controller:

@property (copy, nonatomic) NSString *path;
@property (strong, nonatomic) PageViewController *page;

Then in the pdf view controller

- (void)viewDidLoad {
    [super viewDidLoad];

    PageViewController *page = [[PageViewController alloc] initWithPDFAtPath:self.path];
    page.view.frame = self.view.bounds;
    [self.view addSubview:page.view];
    [self addChildViewController:page];
    self.page = page;
}