2012-12-01 17 views
1

我創建了一個UITableView,其中我調整了節頭的高度和背景。這一切都按預期工作,但其下方的單元(行)變小。幾乎看起來,節標題覆蓋了第一個單元格。 有沒有辦法解決這個問題?或者我應該問,如何解決這個問題?iPhone當增加UITableView節頭的高度時,它下面的單元高度會減小。如何避免?

我節頭的代碼:

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)]; 

    UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, tableView.bounds.size.width, 30)]; 
    headerLabel.text = [self tableView:tableView titleForHeaderInSection:section]; 
    headerLabel.font = [UIFont boldSystemFontOfSize:16]; 
    [headerLabel setTextColor:[UIColor whiteColor]]; 
    headerLabel.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"menuSectionBg.png"]]; 

    [headerView addSubview:headerLabel]; 

    return headerView; 
} 

回答

2

你不應該調整的細胞的意見高度,而是落實在UITableViewDelegate實施

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section; 

方法。

在單元格創建之前計算單元格的高度。

+0

工作完美!謝謝。 – iJar

相關問題