How can I load storyboard programmatically from class?(如何以编程方式从课堂加载故事板?)
问题描述
我的问题是我正在寻找同时使用 storyboard 和 xib 的方法.但是我找不到以编程方式加载和显示故事板的正确方法.项目开始使用 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];
这篇关于如何以编程方式从课堂加载故事板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何以编程方式从课堂加载故事板?
基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
