簡體   English   中英

Objective-C當前視圖控制器及其導航控制器

[英]Objective-C Present View Controller with its Navigation Controller

我有一個如下圖所示的視圖控制器:

在此處輸入圖片說明

我試圖從另一個視圖控制器中呈現此視圖控制器,如下所示:

LHPDFFile *vc = [[LHPDFFile alloc] init];

vc.previewItemURL = self->_previewItemURL;

UINavigationController *navBar=[[UINavigationController alloc]initWithRootViewController:vc];

[self presentViewController:navBar animated:YES completion:nil];

這有效,但是我的按鈕沒有出現:(

似乎上面的代碼創建的是導航控制器,而不是使用我的按鈕。 我究竟做錯了什么?

嘗試使用情節提要實例化視圖控制器。 就像是:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"YourStoryboardName" bundle:nil];
LHPDFFile *vc = (LHPDFFile *)[storyboard instantiateViewControllerWithIdentifier:@"<id of your view controller in the storyboard>"];

調用empty init方法會導致視圖的空實例化,因為您從未提到過應該使用此情節提要的this視圖控制器。 更多細節在這里

init從情節提要中init任何控制器! 這些按鈕屬於file視圖控制器。 您應該從情節提要中 init該控制器,而不是調用init

MyViewController *vc = [[self storyboard] instantiateViewControllerWithIdentifier: @"MyViewControllerStoryBoardID"];

UINavigationController *navBar = [[UINavigationController alloc]initWithRootViewController:vc];

[self presentViewController:navBar animated:YES completion:nil];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM