让UITableView 的 headerView跟随 cell一起滚动,tableHeaderView

在进行UITableView开发的时候,我们有时希望在cell的上面放置一些按钮之类的空间,又想让这些空间跟着cell一起滚动,
刚开始想着hederView,注意,这是tableView的section的hederView,代码如下
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 160; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section; { UIView *view = [[UIView alloc] init]; view.backgroundColor = [UIColor whiteColor]; return view; } 后来发现这样不行,在网上搜到这篇文章
http:
//blog.csdn.net/tangaowen/article/details/64523,受这篇文章启发,
原来UITableVIew有个属性tableHederView,于是可以这样设(注意这是UITableView的HederView)

UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
view.backgroundColor = [UIColor blackColor]; self.tableView.tableHeaderView = view;

图中黑色是UITableView的HederView ,白色是tableView的section的hederView,这里只有一个section.

原文地址:https://www.cnblogs.com/shanyimin/p/4358036.html