构建xib Interface Builder并将其作为子视图加载到iphone中 [英] Build xib Interface Builder and load them as subview in iphone
问题描述
我想知道是否可以构建视图及其对应的xib文件。
然后,在通用控制器中,以编程方式加载此视图并将其作为子视图添加到当前视图。
what I would like to know if it's possible to build a view and its correspondent xib file. Then, in a generic controller, load this view programmatically and add as a subview to the current view.
此子视图应充当通用信息框,可以由许多控制器加载。
This subview should act as a generic info box which can be loaded by many controller.
谢谢
Leonardo
thanks Leonardo
推荐答案
在查看了一些stackoverflow线程后,我自己找到了解决方案。所以我想分享我发现的内容,看看它是否是可接受的解决方案。
基本上这就是我所做的:
I found solution myself, after looking at some stackoverflow thread. So I would like to share what I found and see if it's an acceptable solution. Basically this is what I did:
- 创建
MyView.m
查看包含我所需的所有IBOutlet的文件 - 在界面构建器中构建一个
MyView.xib
视图,将默认文件的所有者和设置视图保留为MyView.m
-
使用这段代码
- create a
MyView.m
view file with all my required IBOutlet - build a
MyView.xib
view in interface builder, leaving default file's owner and set view asMyView.m
use this piece of code
NSArray *xib = [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil];
MyView * myView = [xib objectAtIndex:0];
[self addSubview:myView];
它确实有效......
It works, actually...
这篇关于构建xib Interface Builder并将其作为子视图加载到iphone中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!