ios - 直到滚动才显示 uitableview 标题背景

标签 ios uitableview

我使用以下代码来设置 uitableview 部分的标题 View 。问题是,在我滚动表格 View 之前,背景颜色 (mainLightColor_2) 不会显示。如何使背景颜色在加载时显示?

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 24)];
  headerView.backgroundColor = [Utility mainLightColor_2]; //mainLightColor is a blue color

  UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 2, 200, 20)];
  label.backgroundColor = [UIColor clearColor];
  label.textColor = [Utility mainDarkColor];
  label.text = @"Past Activities";
  [headerView addSubview:label];

  return headerView;
}

滚动前: Before scroll

滚动后: After scroll

最佳答案

您还应该实现 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 方法。

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 24;
}

关于ios - 直到滚动才显示 uitableview 标题背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16633177/

相关文章:

ios - Swift:UICollectionViewCell中的UIButton图像不会改变

swift - 更改选项卡后 UITableView 部分标题 float

ios - 即使我设置了 TableView.separatorStyle = .none,UITableViewCell 之间的细线间隙也是可见的

ios - NSMutableArray removeObjectAtIndex 在第二次执行时崩溃

ios - 导航模式下不显示文本说明 (Mapbox iOS)

objective-c - 显示应用的构建日期

android - Facebook 应用程序提交

ios - 仅在尚未选择单元格时显示 View Controller ?

ios - 在 swift 3 的不同部分的 TableView 中执行互斥选择的最佳方法

ios - 当我在 UITableViewController 上滚动时,描述标签消失