2011-12-02 30 views
1

我使用以下代码创建了自定义部分标题,但没有显示红色标签。自定义表部分标题不起作用

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    UIView *headerView = [[[UIView alloc] init] autorelease]; 

    UILabel * label1 = [[UILabel alloc] init]; 
    label1.textColor = [UIColor redColor]; 

    [headerView addSubview:label1]; 

    return headerView; 
} 

回答

1

UILabel指定初始化是-initWithFrame:,而不是-init。您的标签没有出现,因为您没有为视图指定框架。

此外,我注意到你还没有初始化headerView一帧,但似乎工作,因为UITableView可能设置一个新的帧在某一点。您应该养成使用指定初始化程序的习惯。

UIView Class Reference