ios - 从 UIViewcontroller 调用 Storyboard

标签 ios uiviewcontroller modal-dialog storyboard

我不知道这是否可行,但我使用 xibs 编写了一个项目并想以模式方式切换到 Storyboard项目。

我知道要切换 VC,你需要做类似的事情

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

点击一个按钮,我称之为“切换”

还有另一个项目只使用 Storyboard,我想用“switch”调用它

我该怎么做呢?可以这样做吗?

最佳答案

是的,这是可能的。你可以这样做:

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

编辑 如果我理解你的评论,你想更改 Root View Controller 。你可以这样做:

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

请注意,要使其正常工作,您必须在您的 RVCStoryboard 中选择您尝试加载的 View Controller ,并为其分配一个名称,以便 instantiateViewControllerWithIdentifier: 方法能够正常工作。检查附加图像,字段“ Storyboard ID”: enter image description here

关于ios - 从 UIViewcontroller 调用 Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21411079/

相关文章:

iphone - NSMutableArray removeObjectAtIndex

javascript - 从 PHP 脚本中调用 jQuery 模态

c# - 在 WPF MVVM 模式中打开子窗口 - 正确的解决方案?

ios - NSDateComponents 在模拟器上运行

ios - WatchKit:将数据从第三个 Controller 传递到初始 Controller

iphone - 在进入后台和在前台检索时将 NSTimer 的时间保存到磁盘

iphone - 当我们执行 presentViewController 时,幕后会发生什么?

ios - 来自服务器的数据未显示在 TableView 中

ios - 将动态创建的 UIView 置于 Storyboard 中的 UILabel 的中心无法正常工作

javascript - 在 div 单击时显示和隐藏弹出窗口