简体   繁体   中英

Objective-C Present View Controller with its Navigation Controller

I have a view controller like in the image below:

在此处输入图片说明

And I am trying to present this view controller from another view controller like so:

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

vc.previewItemURL = self->_previewItemURL;

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

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

This works, however my buttons are not appearing :(

It appears that the code above is creating a Navigation Controller instead of using mine with the buttons. What am I doing wrong?

Try instantiating your view controller with the storyboard. Something like:

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

Calling the empty init method leads to empty instantiation of the view, because you have never mentioned that it should use this storyboard's this view controller. More details here .

You init none of your controllers from storyboard! Those buttons belongs to file view controller. You should init that controller from storyboard instead of call init .

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM