PrepareforSegue不显示destinationviewcontroller

时间:2013-07-11 18:35:39

标签: iphone objective-c ios6 uistoryboardsegue

segue destinationviewcontroller pdfviewcontroller不显示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;

}
}

仅显示导航栏和后退按钮

并显示语义问题不兼容的指针类型,从pageviewcontroller strong分配给pdfviewcontroller strong。

感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

这一行错了:

  

pdfviewController = page;

正如编译器告诉你的那样,类型为PDFViewController *,而你正在尝试分配PageViewController *

你的意思是:

pdfviewController.page = page;

segue应该这样做:

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

向pdf视图控制器添加一些属性:

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

然后在pdf视图控制器中

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