使用xib文件而不初始化视图控制器 [英] Using a xib file without initializing a view controller

查看:149
本文介绍了使用xib文件而不初始化视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用IB创建一个包含各种工具栏项目的工具栏,但是可以通过编程方式创建和使用这个工具栏 - 根据我的判断将它添加到视图中,而不是初始化视图控制器。

I'd like to use IB to create a toolbar with assorted toolbar items, but create and use this toolbar programatically - adding it to a view at my discretion, and not while initializing the view controller.

我确定可以做到 - 但是找不到一个好的参考。任何帮助?

I'm pretty sure it can be done - but haven't been able to find a good reference. Any help?

推荐答案

请参阅NSBundle的 loadNibNamed:owner:options: / p>

Read about NSBundle's loadNibNamed:owner:options: method:

NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"Toolbar" owner:self options:nil];

这将返回nib中的所有对象,你可以使用简单的数组方法。还要注意,如果nib文件引用任何出口到其他对象在nib - 他们必须在你的控制器(或任何其他给定的nib所有者)中定义,否则你会得到KVC异常。

This will return all the objects in nib which you can get using simple array methods. Also note that if nib file references any outlets to other objects in nib - they must be defined in your controller (or any other given nib owner) as well otherwise you'll get KVC exceptions.

这篇关于使用xib文件而不初始化视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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