gpt4 book ai didi

iOS显示更多来自xib内部 View 的 View

转载 作者:行者123 更新时间:2023-12-01 19:11:12 25 4
gpt4 key购买 nike

我正在开发 iOS 应用程序,但我需要帮助才能在一个 View 中显示来自 xib 文件的更多自定义 View 。

我需要的是这样的:

Layout

您可以看到一个 Root View 、一些标签和 3 个自定义 subview 。每个 subview 都有自己的 xid 文件,但我不知道如何将它们彼此相邻显示。

我在界面生成器中放置了三个 View ,我认为我只是创建了三个 UIView socket ,并使用 loadNibName 方法对其进行了初始化,但它不起作用。这是来自 Controller 的代码:

@interface ViewController_iPad () {

__strong IBOutlet UIView *view1;
__strong IBOutlet UIView *view2;
__strong IBOutlet UIView *view3;
}

@end



- (void)viewDidLoad
{
[super viewDidLoad];

NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil];
view1 = [nibContents objectAtIndex:0];

nibContents = [[NSBundle mainBundle] loadNibNamed:@"MyView2" owner:self options:nil];
view2 = [nibContents objectAtIndex:0];

nibContents = [[NSBundle mainBundle] loadNibNamed:@"MyView3" owner:self options:nil];
view3 = [nibContents objectAtIndex:0];

}

使用此代码, subview 为空,并且不显示包含来自 xib 文件的内容。

你能告诉我我做错了什么吗?或者如果这是一个好方法如何做到这一点?我应该使用一些容器而不是 subview 吗?比你

最佳答案

采用

 NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil];
[view1 addSubview:[nibContents objectAtIndex:0]];

代替
view1 = [nibContents objectAtIndex:0];

关于iOS显示更多来自xib内部 View 的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16481001/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com