简体   繁体   English

从UIViewcontroller调用storyboard

[英]Calling storyboard from UIViewcontroller

I don't know if this is possible or not but I wrote a project using xibs and want to modally switch to a storyboard project. 我不知道这是否可能,但我使用xib编写了一个项目,并希望以模态方式切换到storyboard项目。

I know that to switch VC's you do something like 我知道要切换VC,你会做类似的事情

NewViewController *NewVC = [[NewViewController alloc] init];
[self presentModalViewController:NewVC animated:YES];

upon clicking a button, that I'll call "switch" 点击一个按钮,我称之为“开关”

There is another project using solely storyboards that I want to call using "switch" 还有另一个项目使用故事板,我想用“开关”调用

How do I go about doing this? 我该怎么做呢? Is it possible to do this? 是否有可能做到这一点?

Yes it is possible. 对的,这是可能的。 You can do something like this: 你可以这样做:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"YourStoryboardName" bundle:nil];
MainMenuViewController *mainmenuvc = [storyboard instantiateViewControllerWithIdentifier:@"mainMenuViewController"];
[self.navigationController pushViewController:mainmenuvc animated:YES];

EDIT If I understand your comment, you want to change the root view controller. 编辑如果我理解您的评论,您想要更改根视图控制器。 You can do so by: 你可以这样做:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"RVCStoryboard" bundle:nil];
MainMenuViewController *mainmenuvc = [storyboard instantiateViewControllerWithIdentifier:@"mainMenuViewController"];
[[UIApplication sharedApplication].delegate].window.rootViewController = mainmenuvc;

Please note that for this to work, in your RVCStoryboard you have to select the viewcontroller you are trying to load, and assign a name to it so that the instantiateViewControllerWithIdentifier: method will work. 请注意,为了使其正常工作,您必须在RVCStoryboard中选择要加载的viewcontroller,并为其指定一个名称,以便instantiateViewControllerWithIdentifier:方法可以正常工作。 Check the attached image, the field "Storyboard ID": 检查附加图像,“故事板ID”字段: 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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