如何从课程中以编程方式加载故事板? [英] How can I load storyboard programmatically from class?

查看:154
本文介绍了如何从课程中以编程方式加载故事板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我正在寻找使用 storyboard xib 的方法。但我找不到以编程方式加载和显示故事板的正确方法。项目开始使用xib开发,现在很难将所有xib文件嵌套在storyboard中。所以我在代码中寻找一种方法,比如使用 alloc,init,push 来实现viewControllers。在我的情况下,我在故事板中只有一个控制器: UITableViewController ,它有静态单元格,包含我想要显示的内容。如果有人知道在没有大量重构的情况下使用xib和storyboard的正确方法,我将非常感谢您的帮助。

My problem is that I was looking for way to use both storyboard and xib. But I can't find proper way to load and show storyboard programmatically. Project was started developing with xib, and now it's very hard to nest all xib files in storyboard. So I was looking a way to do it in code, like with alloc, init, push for viewControllers. In my case I have only one controller in storyboard: UITableViewController, which has static cells with some content I want to show. If anyone knows proper way to work both with xib and storyboard without huge refactoring, I will appreciate for any help.

推荐答案

在你的故事板转到属性检查器并设置视图控制器的标识符。然后,您可以使用以下代码显示该视图控制器。

In your storyboard go to the Attributes inspector and set the view controller's Identifier. You can then present that view controller using the following code.

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"myViewController"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];

这篇关于如何从课程中以编程方式加载故事板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆