![](/img/trans.png)
[英]Pass variable to View Controller Embedded in Navigation Controller in 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.