【问题标题】:iPhone When increasing the height of UITableView section header the height of the cell below it decreases. How to avoid?iPhone 当增加 UITableView 部分标题的高度时,它下面的单元格的高度会降低。如何避免?
【发布时间】:2012-12-01 13:05:19
【问题描述】:

我创建了一个 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;
}

【问题讨论】:

    标签: iphone uitableview sectionheader


    【解决方案1】:

    你不应该调整单元格视图的高度,而是实现

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

    UITableViewDelegate 实现中的方法。

    甚至在创建单元之前计算单元的高度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-02
      • 2012-08-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多