使用不带外部xib的故事板添加子视图 [英] Add subview using storyboard without external xib

查看:174
本文介绍了使用不带外部xib的故事板添加子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在学习Objective-C。

I'm learning Objective-C.

我有一个新的故事板功能的问题。我将使用xib在主视图内初始化一个子视图。

I have a problem with new storyboard feature. I would initialize a subview inside a main view with xib.

没有使用故事板,我可以使用:

Without using storyboard, I could do it using:

controller = [[UIViewController alloc]initWithNibName:@"NibName" bundle:nil];
[self.view addSubview:controller.view];

现在,我不会使用外部xib,但是我想在类中管理一个视图,使用它像另一个类中的子视图。

Now, I wouldn't use an external xib, but I want manage a view in a class and use it like a subview in another class.

我知道可以使用xib并使用类似的代码加载它,但它必须在故事板上。

I know that is possible use a xib and use a similiar code to load it, but it must be out the storyboard.

推荐答案

首先在您的故事板中创建视图,然后使用以下代码进行实例化。此外,请务必通过Attributes Inspector为其指定标识符。

First create the view in your storyboard and then instantiate it with the following code. Also make sure you give it an identifier via the Attributes Inspector.

controller = [self.storyboard instantiateViewControllerWithIdentifier:@"identifier"];
[self.view addSubview:controller.view];

这篇关于使用不带外部xib的故事板添加子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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