如何在情节提要中创建 UIViewController 布局,然后在代码中使用它? [英] How to create a UIViewController layout in storyboard and then use it in code?

查看:21
本文介绍了如何在情节提要中创建 UIViewController 布局,然后在代码中使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 iOS 5 应用程序中有一个 Storyboard.

I have a Storyboard in my iOS 5 application.

在那里我创建了许多屏幕,并且效果很好.

In there I have created a number of screens and it works perfectly.

但是,我在代码中创建了一个视图控制器,不是作为 UI 操作的结果,而是在处理数据结束时.然后,我想将这个视图控制器显示为 modalViewController,但也要在情节提要编辑器中设计它.

However there's one view controller that I create in code, not as a result of UI action but at the end of processing data. I would like to show this view controller then, as a modalViewController, but also have it designed in the storyboard editor.

有可能吗?使用笔尖我是这样做的:

Is it possible? Using the nibs I did it like this:

ResultsController *rc = [[ResultsController alloc] initWithNibName:@"ResultsController"
                                                            bundle:nil];
[self.navigationController presentModalViewController:rc animated:YES];
[rc release];

现在我真的没有 nib 文件,我该怎么做呢?

Right now I don't really have a nib files, so how do I do it?

推荐答案

看看 UIStoryboard 类.有一个 instantiateViewControllerWithIdentifier 方法.因此,您需要在 Storyboard Editor 中为 ResultsController ViewController 设置 Identfier.

Take a look at the UIStoryboard class. There is a instantiateViewControllerWithIdentifier Method. So you need to set the Identfier within the Storyboard Editor for your ResultsController ViewController.

你可以这样做

UIViewController *viewController = 
   [[UIStoryboard storyboardWithName:@"MainStoryboard" 
                              bundle:NULL] instantiateViewControllerWithIdentifier:@"ResultsController"];

[self presentModalViewController:viewController animated:NO];

这篇关于如何在情节提要中创建 UIViewController 布局,然后在代码中使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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