如何在情节提要中创建 UIViewController 布局,然后

How to create a UIViewController layout in storyboard and then use it in code?(如何在情节提要中创建 UIViewController 布局,然后在代码中使用它?)
本文介绍了如何在情节提要中创建 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 布局,然后在代码中使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
Android IllegalArgumentException: The tag for fragment_XXX is invalid. Received: layout-sw600dp/fragment_XXX_0(Android IlLegalArgumentException:Fragment_XXX的标签无效。收到:Layout-sw600dp/Fragment_XXX_0)
iOS convert audio sample rate from 16 kHz to 8 kHz(IOS将音频采样率从16 kHz转换为8 kHz)
Enforcing an audio sampling rate in iOS(在iOS中强制音频采样率)
HTTPS request using volley(使用 volley 的 HTTPS 请求)