2013-07-10 91 views
1

我有pageviewcontroller,我想用故事板如果我用這個語句顯示Pageviewcontroller用故事板賽格瑞

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

那麼它不顯示導航顯示在這個項目和Segue公司

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

酒吧和backbarbuttonitem

當我刪除此聲明

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

然後它不顯示pageviewcontroller使用捲曲效果轉換翻頁只有它顯示導航欄和backbarbuttonitem。

,當我有這種說法

[self.view addSubview:page.view]; 

代替這種說法

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

然後顯示pageviewcontroller但不轉頁上都沒有。

請幫忙。

非常感謝。

+0

您是試圖以模態呈現PageViewController還是將其推送到導航堆棧上?或者您是否使用自定義的Segue來呈現PageViewController? – Bradford2000

+0

使用push segue – user1120133

回答

1

我想我看到你的問題。由於您在故事板中設置了segue,因此不必調用presentViewController。我想你真正想要的prepareForSegue函數做:

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

另外,如果推SEGUE沒有內置到故事,你應該能夠有一個修改使用當前的代碼:

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

希望這會有所幫助。

+0

但是在準備segue我有PDFViewController * pdfviewController = [segue destinationViewController];如果我添加你的行然後我得到這個錯誤終止應用程序由於未捕獲異常'NSInvalidArgumentException',原因:' - [PDFViewController initWithPDFAtPath:]:無法識別的選擇發送到實例 – user1120133

+0

好吧,你可能需要確定是否繼續。在執行邏輯之前,destinationViewController是一個PageViewController。看到我更新的答案。 – Bradford2000

+0

除了PageViewController之外,你還有其他的主視圖控制器嗎?如果沒有,您可能需要確保故事板的頁面視圖的Class屬性設置爲PageViewController,而不是UIViewController(或其他)。 – Bradford2000