再添加tableviewheader時注意

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

使用此方法添加header的时候,header不会随着tableview的滚动而滚动

需要注意,重写自定义header(继承自uiview)的setFrame方法,

- (void)setFrame:(CGRect)frame

{

    CGRect sectionRect = [self.tableView rectForSection:self.section];

    CGRect resultFrame = CGRectMake(CGRectGetMinX(frame), CGRectGetMinY(sectionRect), CGRectGetWidth(frame), CGRectGetHeight(frame));

    [super setFrame:resultFrame];

}

原文地址:https://www.cnblogs.com/ganeveryday/p/5138628.html