UIView和XIB连接.显示它
UIView and XIB connections.Displaying it?
如何在UIView上显示XIB/NIB文件?我找过了,但没找到这个。我想在主视图上显示xib接口,我有五个xib文件,我需要在UIView上显示每个xib文件!有些人说这段代码是代码,但我要实现的是:
NSArray *screens=[[NSBundle mainBundle] loadNibNamed:@"JaneiroClass" owner:self options:nil];
[self addSubview:[screens objectAtIndex:0]];
这将从XIB加载视图。UINib还可以缓存,因此您可以快速删除它们。
UINib *nib = [UINib nibWithNibName:@"TestView" bundle:nil];
UIView *myView = [[nib instantiateWithOwner:self options:nil] objectAtIndex:0]];
instantiateWithOwner返回XIB中顶层对象的数组。在上面的例子中,只有一个视图(上面有库中的其他对象),所以我们检索objectAtIndex:0.
一旦有了视图,就可以将其添加到其他视图中。例如,你可以在另一个视图上调用addSubView,传递这个:
[someView addSubView:myView];
我在我的博客http://effectivemobility.blogspot.com/2011/05/using-custom-cells-in-your-uitableview.html上发表了一篇关于从nib加载自定义视图的文章
关键部分是这个方法
+ (id)customViewForClass:(Class)customClass {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(customClass) owner:nil options:nil];
for ( id currentObject in topLevelObjects ) {
if ( [currentObject isKindOfClass:customClass] ) {
return currentObject;
}
}
return nil;
}
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 字符串-C++后显示的随机字符
- 继承期间显示未知行为的子类
- 仅使用绝对值对数组进行排序,并在C++中显示实际值
- 当套接字连接断开时检测C/C++Unix
- 程序崩溃并显示"std::out_of_range"错误
- 如何在C++中用std::cout正确显示带十六进制的字符串文本
- 为什么在C的循环中使用printf的Rust代码不显示输出,而在C++的循环中显示std::cout
- 从数据库实时显示QT c++中的数据
- 将移动设备(iOS和Android)连接到带有QT / C++和镜像显示的VNC服务器
- 在为C 设置NetBean时,它显示了未连接的构建主机
- vcpkg 安装失败,并显示"SSL 连接错误"
- 如何将QT Combobox与PushButton和某种显示图片的小部件连接
- SDL视频显示窗口:如何连接窗口关闭事件回调
- 有没有办法确保连接到注册表中显示的串行端口的设备可以使用
- 微控制器显示驱动程序需要在C或c++中进行不寻常的字符串连接
- 无法连接到端口,但 netstat 显示哪个端口正在侦听
- UIView和XIB连接.显示它
- 在单个字符串中显示Unicode QString的QLatin1String连接