[英]Custom table header section
我有一個團體風格表的應用程序。
我試圖自定義表頭部分:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
UILabel *userName = [[UILabel alloc] initWithFrame:CGRectMake (0,0,200,30)];
if (section != 0)userName.text = @"lalala";
[userName setFont:[UIFont fontWithName:@"HelveticaNeue" size:20]];
[headerView addSubview:userName];
[headerView setBackgroundColor:[UIColor clearColor]];
[userName setBackgroundColor:[UIColor clearColor]];
return headerView;
}
但我的標題關閉了細胞:
為什么?
您還需要實現tableView:heightForHeaderInSection:
為節標題設置正確的高度。 請參閱Apple文檔
發生這種情況是因為標頭的高度設置為0,直到您覆蓋另一個委托:
- tableView:heightForHeaderInSection:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.