【技巧】UITableView 在UITableViewStylePlain模型下,取消headerView的黏结性,不浮动
来源:互联网 发布:php warning 编辑:程序博客网 时间:2024/04/30 02:50
UITableView使用UITableViewStylePlain样式时,section的header与footer会在滚动过程中固定在顶部,这个交互很不错。如果要阻止这个交互,那么办法有几个:
1. 样式改成UITableViewStyleGrouped,但是在iOS6上需要做很多样式调整才能达到与UITableViewStylePlain一致;
2. 每个section多加行来模拟header或footer,但是代码维护难度更大;
3. 继承UITableView,覆盖方法-allowsHeaderViewsToFloat或-allowsFooterViewsToFloat,但是使用了私有API审核有风险;
4. 自定义header或者footer阻止浮动, 重写tableview的frame
5. 假装cell为header。
(完)
2. 每个section多加行来模拟header或footer,但是代码维护难度更大;
3. 继承UITableView,覆盖方法-allowsHeaderViewsToFloat或-allowsFooterViewsToFloat,但是使用了私有API审核有风险;
4. 自定义header或者footer阻止浮动, 重写tableview的frame
5. 假装cell为header。
以上种种方法带有破坏性,入侵性:动不动修改frame和contentInset。现在介绍一个巧妙方法,使用简单。
设计思路:
普通的section,cell多的话滑动时候超过一屏的高度,绿色的header会停留在section的top并浮动。如图1:
那么如果section中的cell为空,它是不会浮动的;基于这个原理,可以巧妙的将header单独拎出来。如图2:试想分拆后的每一个section,只有第一个带有header,且不会浮动。为了扩展性,将footer也算进去。
一图省千语啊
UITableViewDelegate UITableViewDataSource
将原始的section数量乘以3,得到header的section,cell的section,footer的section。
#pragma mark —————header——————- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (section%3 == 0) { /*正常的header 高度*/ return headerHeight; } return 0;}- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if (section%3 == 0) { /*正常的header*/ return headerView; } return nil;}#pragma mark —————cell——————- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (section%3 == 1) { /*正常的cell 高度*/ return cellHeight; } return 0;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (section%3 == 1) { /*正常的cell*/ return cell; } return nil;}#pragma mark —————footer——————- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ if (section%3 == 2) { /*正常的footer 高度*/ return footerHeight; } return 0;}- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { if (section%3 == 2) { /*正常的footer*/ return footerView; } return nil;}
(完)
1 0
- 【技巧】UITableView 在UITableViewStylePlain模型下,取消headerView的黏结性,不浮动
- UITableView UITableViewStylePlain模型下 取消headerView的黏结性
- UItableView处于UITableViewStylePlain模式下如何取消HeaderView粘连性
- UITableView在Plain类型下,HeaderView和FooterView不悬浮和不停留的方法
- 让UITableView的section header view不悬停,让UITableView的section headerview取消粘性
- tableview 的格式为UITableViewStylePlain,去掉headerview的黏连性
- UITableView UITableViewStylePlain 和 UITableViewStyleGrouped的区别
- 解决IOS中UITableViewStylePlain 时对headerview的隐藏
- 解决UITableViewStylePlain方式headerView顶端 滞留的代码
- UITableView 取消headerView的黏性,但是不能取消footerView的黏性
- 让UITableView的headerview不悬停的方法
- 如何让UITableView的section headerView不悬停
- 使 UITableViewStylePlain Style 的TableView header 不浮动,像Group Style 那样固定,跟随Tableview 滚动,而不会停在顶端。
- UITableView UITableViewStylePlain UITableViewStyleGrouped
- UITableView UITableViewStylePlain UITableViewStyleGrouped
- UITableView的headerView悬停解决方案
- UITableView headerView头视图的复用
- 改变UITableView的headerView、footerView背景颜色
- 各种排序算法总结(C++实现)
- Date类型
- Android 开发Ubuntu下 adt 手机连接开发
- 继承与this关键字
- gcc、make、makefile、cmake、cmakelists区别
- 【技巧】UITableView 在UITableViewStylePlain模型下,取消headerView的黏结性,不浮动
- 从第一个字符串中删除在第二个字符串中出现过的所有字符
- java环境变量配置
- 优化问题与KKT条件
- 8.5 filecmp--文件和目录比较处理
- 字符数组和字符指针
- hdoj 1823 Luck and Love 【二维线段树】
- java代理模式
- HDU破百,ACM起航