PrepareforSegue not displaying destinationviewcontroller

天大地大妈咪最大 提交于 2019-12-11 20:01:16

问题


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;
}


来源:https://stackoverflow.com/questions/17600889/prepareforsegue-not-displaying-destinationviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!