[英]Custom view designed in interface builder not showing
I have created a nib file "tableHeaderView" where i have added some labels and images. 我创建了一个笔尖文件“ tableHeaderView”,在其中添加了一些标签和图像。 I then created a new class "tableHeaderViewClass" as a subclass of UIView and connected the different elements in the nib file to this class.
然后,我创建了一个新类“ tableHeaderViewClass”作为UIView的子类,并将nib文件中的不同元素连接到该类。 Then in interface builder i set the Custom class property of my nib file to: tableHeaderViewClass
然后在界面构建器中,将我的笔尖文件的Custom class属性设置为:tableHeaderViewClass
In my table view controller i was hoping i could do the following: 在我的表视图控制器中,我希望可以执行以下操作:
tableHeaderViewClass *headerview = [[tableHeaderViewClass alloc] initWithFrame:frame];
headerview.titlelabel.text = @"Something";
[self.tableView setTableHeaderView:headerview];
But nothing happens. 但是什么也没发生。 There is no view elements except for the space which the frame defined.
除了框架定义的空间之外,没有视图元素。 What is it i'm missing?
我想念的是什么?
If you created a nib then get an instance from NSBundle loadNibName for your custom view 如果创建了笔尖,则从NSBundle loadNibName获取实例以用于自定义视图
tableHeaderViewClass *headerview = [[[NSBundle mainBundle] loadNibNamed:@"tableHeaderViewClass" owner:self options:nil] lastObject];
headerview.titlelabel.text = @"Something";
[self.tableView setTableHeaderView:headerview];
I assume your nib name is "tableHeaderViewClass" 我假设您的笔尖名称是“ tableHeaderViewClass”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.