0

I have created a nib file "tableHeaderView" where i have added some labels and images. I then created a new class "tableHeaderViewClass" as a subclass of UIView and connected the different elements in the nib file to this class. Then in interface builder i set the Custom class property of my nib file to: 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?

4

1 に答える 1

1

If you created a nib then get an instance from NSBundle loadNibName for your custom view

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"

于 2012-11-05T09:33:46.240 に答える