<分区>
标签 ios objective-c xcode xib
<分区>
我有一个 .m 和 .h 文件链接到一个名为 cusomxib 的 xib。在 xib 中我添加了一个 UIView。
如何通过另一个类以编程方式将标签添加到 myVIew(来自 xib 文件)?如下所示,创建 xib 文件的新实例将不起作用,因为它将创建一个新实例。我想访问原始版本。
这是我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 200)];
[self.label setText:@"This is a label"];
xibView *myxibView = [[xibView alloc] init]; // This is the part thats wrong. I need to use something that just gets the file, not create a new one.
[myxibView.myView addSubview:self.label];
}
希望这足够清楚。如果您需要我澄清一些事情,我很乐意。
最佳答案
- (void)viewDidLoad {
[super viewDidLoad];
self.label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 200)];
[self.label setText:@"This is a label"];
[self.view addSubview:self.label];
}
关于ios - 通过另一个类以编程方式将对象添加到 xib 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28290716/