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

查看:358
本文介绍了如何在故事板中创建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.

有可能吗?使用nibs我这样做:

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方法。因此,您需要在StoryController中为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天全站免登陆