iOS开发中不让UITableView的section头部视图停留

不让UITableView的section头视图停留的实现方式有两种

  1. 直接使用UITableViewStyleGrouped样式的TableView
  2. 重写自定义的section的headerView的setFrame方法

第一种方式不用多说,直接说第二种实现方式。
代码:

  - (void)setFrame:(CGRect)frame {
CGRect sectionRect = [self.tableView rectForSection:self.section];
CGRect newFrame = CGRectMake(CGRectGetMinX(frame), CGRectGetMinY(sectionRect), CGRectGetWidth(frame), CGRectGetHeight(frame));
[super setFrame:newFrame];
}

注意:要先获取headerView所在的tableView以及section。

本篇文章到这里就结束了,愿大家加班不多工资多,男同胞都有女朋友,女同胞都有男朋友。

你可能感兴趣的:(iOS开发中不让UITableView的section头部视图停留)