为什么“loadNibNamed”方法返回数组? [英] Why "loadNibNamed" methods return array?
问题描述
当我们使用loadNibNamed方法获取nib文件时,为什么会返回一个数组,是不是nib文件名对应一个nib文件?我尝试打印这个数组的计数,我发现它总是返回1.我希望你能帮我解释一下,谢谢你!以下是代码片段:
When we use the loadNibNamed method to get nib file, why will return a array, is not a nib file name corresponds to a nib file? I try to print this array's count, I found it always return 1. I hope you can help me to explain, thank you every much! Here is the snippet of code :
NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"TestView" owner:self options:nil];
NSLog(@"array's count is %ld",array.count);
推荐答案
xib返回数组的原因是。XIB可以包含多个视图。优点是您不必为一个视图创建一个xib文件。您只需将多个视图放入一个XIB并从数组中访问它
The reason that xib return an array is that ".XIB" can contain multiple views. The advantage is that you don't have to create one xib file for one view. You simply just put multiple views into one XIB and access it from an array
示例
.Xib - > array [view1,view2,view3,view4]
Example
.Xib --> array[view1, view2, view3, view4]
你可以从图片中看到
You can see from image
这篇关于为什么“loadNibNamed”方法返回数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!