(转) 如何让 UITableView 的 headerView跟随 cell一起滚动
2015-06-03 11:38
471 查看
在我们利用 UITableView 展示我们的内容的时候,我需要在顶部放一个不同于一般的cell的 界面,这个界面比较独特。
1。 所以我就把它 作为一个section的 headerView。
也就是在函数:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
里面返回 这个UIView。
但是,由于这个UIView占的空间很大,基本占用整个屏幕的高度,而滚动tableView的时候,只滚动cell的内容,而这个section的
headerView却不跟着滚动。
后面,我想出了方法2。
2。 设置 tableView的 style为 UITableViewStyleGrouped,然后让
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
返回1。
这样确实可以让 headerView ,在滚动tableView的时候,跟随着cell的内容一起滚动。但是,我发现,下面的cell都被加上了边框,
而且cell的水平显示范围变窄了。
所以尝试了方法3。
3。 将UIView设置为 整个tableView的headerView,而不是 section 0的headerView
self.tableView.tableHeaderView=header;
这样,就可以完美的满足 headerView跟随cell的内容一起滚动的要求拉。
结论:设置 UIView为 tableView的tableHeaderView即可实现 headerView跟随tableView一起滚动的效果。
(原文链接:/article/2936090.html)
1。 所以我就把它 作为一个section的 headerView。
也就是在函数:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
里面返回 这个UIView。
但是,由于这个UIView占的空间很大,基本占用整个屏幕的高度,而滚动tableView的时候,只滚动cell的内容,而这个section的
headerView却不跟着滚动。
后面,我想出了方法2。
2。 设置 tableView的 style为 UITableViewStyleGrouped,然后让
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
返回1。
这样确实可以让 headerView ,在滚动tableView的时候,跟随着cell的内容一起滚动。但是,我发现,下面的cell都被加上了边框,
而且cell的水平显示范围变窄了。
所以尝试了方法3。
3。 将UIView设置为 整个tableView的headerView,而不是 section 0的headerView
self.tableView.tableHeaderView=header;
这样,就可以完美的满足 headerView跟随cell的内容一起滚动的要求拉。
结论:设置 UIView为 tableView的tableHeaderView即可实现 headerView跟随tableView一起滚动的效果。
(原文链接:/article/2936090.html)
相关文章推荐
- quick-3.5创建功能编译android版本
- 怎么用代码判断Android手机的Rom是MIUI及获取MIUI版本
- UILabel的使用
- UIScrollView控件介绍
- STL系列之五 priority_queue 优先级队列
- BLE/Bluetooth Low Energy
- Druid数据源配置入门(超详细)
- Druid数据源配置入门(超详细)
- ling join 报错The specified LINQ expression contains references to queries that are associated with different cont
- IOS UIButton的一些设置代码
- STL系列之三 queue 单向队列
- iOS学习(4)——UITextField
- STL系列之一 deque双向队列
- 021_02UI之自定义主题和样式
- 对于dequeueReusableCellWithIdentifier:的个人理解
- iOS 根据字体调整UILabel的大小
- ios7 uitableview内容视图下移 20px bug
- hadoop mapreduce模式读取sequence文件
- 交互设计分享(一)
- hadoop单机模式读取sequence文件