iOS - Cell高度不固定的情况处理
2016-04-25 14:56
387 查看
处理方案
方案一
直接使用tableView属性@property (nonatomic) CGFloat estimatedRowHeight NS_AVAILABLE_IOS(7_0); // default is 0, which means there is no estimate
该属性在iOS7.0以后可以使用,例如:
self.tableView.estimatedRowHeight = 40;//估算设置一个不太夸张的值
如果项目仅支持7.0以后系统版本则可以直接使用该属性,配置该属性后,不得使用UITableViewDelegate代理方法:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
方案二
由于tableView代理方法中,调用顺序为1.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
2.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
3.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
则可以在1中先估算一个大概的值,再在2中计算该Cell的高度并且保存在一个数组中,再在3中直接调用相对应的高度
问:为什么直接在3中计算Cell中的值
在tableView中 3的代理方法调用次数相当的频繁,每次对Cell进行展示都会调用该方法,而在2中先进行计算并存储,第二次展示Cell时就不用再次计算,提高了性能。
相关文章推荐
- iOS layer层的转场动画
- iOS中内存管理
- iOS对象数组排序
- iOS 图像的滤镜效果实现
- iOS nslog
- dSYM 崩溃信息分析工具
- iOS打包步骤
- 《Motion Design for iOS》(一)
- 自定义键盘右上角完成按钮
- 预览功能
- Xcode 快捷键。实用且能提高效率
- IOS数组相关
- iOS开发--使用RSA加密
- iOS 显示HTML文本
- iOS巅峰之label描边
- iOS沙盒路径的查看和使用
- block简介与简单使用
- 集成支付宝-iOS
- iOS:.NSRunLoop再理解
- iOS Provisioning Profile(Certificate)与Code Signing详解