xcode 从nib文件加载UIView?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6426629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:18:52  来源:igfitidea点击:

Load UIView from nib file?

iphoneiosxcodeipadinterface-builder

提问by Andrew

I have one large view with a toolbar that allows a user to select how they want data displayed. When they select what data they want displayed, a smaller UIView (contained within the original one) should change to show the data they want displayed.

我有一个带有工具栏的大视图,允许用户选择他们希望如何显示数据。当他们选择想要显示的数据时,较小的 UIView(包含在原始 UIView 中)应该更改以显示他们想要显示的数据。

I would like to load that small UIView from a different nib file, but the toolbar (in the larger view) should not disappear, i.e. I don't want that view larger to go away, only the small view should be changed. I have different nib files for each data view.

我想从不同的 nib 文件加载那个小的 UIView,但工具栏(在大视图中)不应该消失,即我不希望那个更大的视图消失,只应该更改小视图。每个数据视图都有不同的 nib 文件。

How can I load the small UIView from a given nib file?

如何从给定的 nib 文件加载小 UIView?

回答by xhan

I've did this before.

我以前做过这个。

SimpleCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"FriendsCell" owner:self options:nil] objectAtIndex:0];

owner is not necessary. and the index should be the same of the index inside the nib. (the first object(Not the file's ownernor First Response) starts from 0)

所有者是没有必要的。并且索引应该与笔尖内的索引相同。(第一个对象(不是file's owner也不是First Response)从0开始)