UITableView setTableHeaderView
@property(nonatomic, retain) UIView *tableHeaderView
Discussion of [UITableView setTableHeaderView]
The default value is nil. The table header view is different from a section header.
UITableView setTableHeaderView example.
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (headerView == nil) {
[[NSBundle mainBundle] loadNibNamed:@"DetailContactHeader" owner:self options:nil];
headerView.nameLabel.text = [NSString stringWithFormat:@"%@ %@",
[contact objectForKey:@"name"],
[contact objectForKey:@"familyname"]];
if ([[contact allKeys] containsObject:@"pictureurl"]) {
headerView.avatarView.image = [UIImage imageNamed:[contact objectForKey:@"pictureurl"]];
}
}
[self.tableView setTableHeaderView: headerView];
}
{
[super viewWillAppear:animated];
if (headerView == nil) {
[[NSBundle mainBundle] loadNibNamed:@"DetailContactHeader" owner:self options:nil];
headerView.nameLabel.text = [NSString stringWithFormat:@"%@ %@",
[contact objectForKey:@"name"],
[contact objectForKey:@"familyname"]];
if ([[contact allKeys] containsObject:@"pictureurl"]) {
headerView.avatarView.image = [UIImage imageNamed:[contact objectForKey:@"pictureurl"]];
}
}
[self.tableView setTableHeaderView: headerView];
}
Example of [UITableView setTableHeaderView].
For example, in a UITableViewController:
-(void)viewDidLoad
{
// ...
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];
[headerView addSubview:imageView];
UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];
[headerView addSubview:labelView];
self.tableView.tableHeaderView = headerView;
[imageView release];
[labelView release];
[headerView release];
// ...
}
-(void)viewDidLoad
{
// ...
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];
[headerView addSubview:imageView];
UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];
[headerView addSubview:labelView];
self.tableView.tableHeaderView = headerView;
[imageView release];
[labelView release];
[headerView release];
// ...
}
UITableView setTableHeaderView example.
[webView sizeToFit];
CGRect newFrame = headerView.frame;
newFrame.size.height = newFrame.size.height + webView.frame.size.height;
headerView.frame = newFrame;
[self.tableView setTableHeaderView:headerView];
CGRect newFrame = headerView.frame;
newFrame.size.height = newFrame.size.height + webView.frame.size.height;
headerView.frame = newFrame;
[self.tableView setTableHeaderView:headerView];