有关分组TableView的组高设置
2016-04-12 14:34
309 查看
iOS的tableView的模式有2种,一种是UITableViewStylePlain不分组的样式,UITableViewStyleGrouped分组样式。
1、对于不分组的样式,通常实现几个代理方法就能够完成效果,但是有一点就是tableView的headerView不会跟着tableView一起滚动(滚动的时候,会留在页面上面,等待下一个footerView顶上来的时候才会消失);
2、如果要实现footerView随时跟着tableView滚动,就需要设定UITableViewStyleGrouped分组样式。由于tableView的style是readonly,所以只能在创建表的时候设置
如果你用的是xib,在属性栏那里同样可是设置
3、设置成功之后发现运行效果确实是分组模式,footerView也可以跟着滚动了,但是section的高度和预期的不一样,这就需要设置sectionHeaderHeight,sectionFooterHeight的高度了,在没有设置之前,它们的高度都是-1.000000,是系统的默认值。
4、在没有设置sectionHeaderHeight,sectionFooterHeight之前,很多同学刚开始可能会选择实现代理方法
但会发现组高的确实发生了变化,但是所有的组高并不相等,然后实现方法
会发现仍没有太大变化,就不知所措了,没关系,不用上面的方法,我们可以试一下下面方法:
这时你会发现section=0 的时候并没有变化,所以我们还需要
到此为止,自定义高度就完成了,并且想要改变组高,只需要修改sectionHeaderHeight或者sectionFooterHeight就行了,当然也可以在代理方法中判断section来修改。
5、总结一下:最后发现self.tableView.sectionHeaderHeight = 20;可以不用设置,直接用代理的方法就可以,但是self.tableView.sectionFooterHeight = 0必须写。
并且如果写了self.tableView.sectionFooterHeight = 0之后,他的代理方法其实是不起作用的。简单来说,就是只需实现下面的代码:
就完成了。
1、对于不分组的样式,通常实现几个代理方法就能够完成效果,但是有一点就是tableView的headerView不会跟着tableView一起滚动(滚动的时候,会留在页面上面,等待下一个footerView顶上来的时候才会消失);
2、如果要实现footerView随时跟着tableView滚动,就需要设定UITableViewStyleGrouped分组样式。由于tableView的style是readonly,所以只能在创建表的时候设置
-(instancetype)init{ if (self = [super initWithStyle:UITableViewStyleGrouped]) { } return self; }
如果你用的是xib,在属性栏那里同样可是设置
3、设置成功之后发现运行效果确实是分组模式,footerView也可以跟着滚动了,但是section的高度和预期的不一样,这就需要设置sectionHeaderHeight,sectionFooterHeight的高度了,在没有设置之前,它们的高度都是-1.000000,是系统的默认值。
4、在没有设置sectionHeaderHeight,sectionFooterHeight之前,很多同学刚开始可能会选择实现代理方法
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 10; }
但会发现组高的确实发生了变化,但是所有的组高并不相等,然后实现方法
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 80; }
会发现仍没有太大变化,就不知所措了,没关系,不用上面的方法,我们可以试一下下面方法:
self.tableView.sectionHeaderHeight = 20; self.tableView.sectionFooterHeight = 0;
这时你会发现section=0 的时候并没有变化,所以我们还需要
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return tableView.sectionHeaderHeight; }
到此为止,自定义高度就完成了,并且想要改变组高,只需要修改sectionHeaderHeight或者sectionFooterHeight就行了,当然也可以在代理方法中判断section来修改。
5、总结一下:最后发现self.tableView.sectionHeaderHeight = 20;可以不用设置,直接用代理的方法就可以,但是self.tableView.sectionFooterHeight = 0必须写。
并且如果写了self.tableView.sectionFooterHeight = 0之后,他的代理方法其实是不起作用的。简单来说,就是只需实现下面的代码:
self.tableView.sectionFooterHeight = 0; - (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 30; }
就完成了。
相关文章推荐
- myeclipse测试数据库连接
- 从今天起,开始记录一些关于Android的问题或者文章
- 浏览器缓存机制
- 使用coreData
- android studio运行程序找不到class,java.lang.ClassNotFoundException: Didn't find class,完美解决!
- 前端直接调用OC的native方法
- 用已学布局和控件画一个登陆界面
- yum使用详解
- 类字面变量
- 启动tomcat 服务报 The file is absent or does not have execute permission
- iOS开发系列--视图切换
- 七号信令的消息结构(包括SCCP详解)
- Unity3D 学习笔记9 —— 3D模型动画控制
- java学生成绩管理系统
- 码农小汪-spring框架学习之9-基于 Java 的配置元数据 @ImportResource
- 怎样在MyEclipse上耍Chrome
- 【JS】:JS 日期类的使用
- Viewpager+fragment数据更新问题解析
- Cocos2d-JS 精灵的性能优化
- centos 单独安装apachebench