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

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

问题描述

我的问题是我正在寻找同时使用 storyboardxib 的方法.但是我找不到以编程方式加载和显示故事板的正确方法.项目开始使用 xib 开发,现在很难将所有 xib 文件嵌套在情节提要中.所以我一直在寻找一种在代码中执行此操作的方法,例如对 viewControllers 使用 alloc, init, push.在我的例子中,我在情节提要中只有一个控制器:UITableViewController,它有一些我想要显示的内容的静态单元格.如果有人知道在不进行大量重构的情况下使用 xib 和故事板的正确方法,我将不胜感激.

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天全站免登陆