使用第三方UITableView+FDTemplateLayoutCell计算cell行高注意点
现在很方便的计算单元格的行高大部分都是使用的第三方框架UITableView+FDTemplateLayoutCell,不知道你在使用这个框架的时候有没有遇到和我一样的问题,比如:
在这样计算cell的高度的时候崩溃了.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return [tableView fd_heightForCellWithIdentifier:PersonDataCellIdentify configuration:^(id cell) {
[self configurePersonDataTableViewCell:cell atIndexPath:indexPath];
}];
}

崩溃原因是必须注册cell......然后反复检查代码.
1.自己明明都有写注册cell的代码,,identify也木有错误,就是不知道为什么崩溃;
2.以为是cell的布局有问题,导致不能自己计算单元格的行高;
其实原因很简单,不知道你得问题是啥,总之我的问题就是一行代码的位置问题.
原因就是:
self.tableView.tableFooterView = [[UIView alloc]init];这句代码在注册cell之前,导致的崩溃.
因为你在设置表视图的tableFooterView的时候,他就会走tableView的数据源和代理方法,而这个时候你还没有注册cell,导致他认为你还没有注册cell,导致崩溃.
#pragma mark - 设置界面
- (void)setUI {
self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(, , K_SCREEN_WIDTH, K_SCREEN_HEIGHT) style:UITableViewStylePlain];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.separatorInset = UIEdgeInsetsMake(, , , );
self.tableView.tableFooterView = [[UIView alloc]init];
// 注册cell
// [_tableView registerNib:[UINib nibWithNibName:@"AddTableViewCellWithLabel" bundle:nil] forCellReuseIdentifier:ADD_LABEL_CELL_ID];
[_tableView registerClass:[PersonDataCell class] forCellReuseIdentifier:PersonDataCellIdentify];
[self.view addSubview:self.tableView];
}
解决办法就是: 先注册cell,再设置tableFooterView就好了....
#pragma mark - 设置界面
- (void)setUI {
self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(, , K_SCREEN_WIDTH, K_SCREEN_HEIGHT) style:UITableViewStylePlain];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.separatorInset = UIEdgeInsetsMake(, , , );
// 注册cell
// [_tableView registerNib:[UINib nibWithNibName:@"AddTableViewCellWithLabel" bundle:nil] forCellReuseIdentifier:ADD_LABEL_CELL_ID];
[_tableView registerClass:[PersonDataCell class] forCellReuseIdentifier:PersonDataCellIdentify];
self.tableView.tableFooterView = [[UIView alloc]init];
[self.view addSubview:self.tableView];
}
持续记录自己在工作中遇到的问题和解决方法,希望学到更多的知识.
使用第三方UITableView+FDTemplateLayoutCell计算cell行高注意点的更多相关文章
- UITableView+FDTemplateLayoutCell计算行高显示<二>
之前记录过一篇UITableView+FDTemplateLayoutCell计算行高不成功的博客... 传送门:http://www.cnblogs.com/pengsi/p/6571311.htm ...
- tableView计算动态行高的总结
研究tableView怎么计算动态行高研究了两天一直还不太会,今天最终做出来了想要的效果. 首先.我在网上搜集了非常多资料,各种大神的总结,然后開始看.研究.试验,基本思路都是一样的. 1.一定要将l ...
- 对tableView三种计算动态行高方法的分析
tableView是一个神奇的东西,可以这么说,就算是一个初学者如果能把tableView玩的很6,那编一般的iOS的需求都问题不大了.tableView是日常开发中用烂了的控件,但是关于tableV ...
- IOS第八天(5:UITableViewController新浪微博, 计算行高)
在 4 的 基础上重写 以下的方法 control #pragma mark - 代理方法 /** 计算单元格行高 */ - (CGFloat)tableView:(UITableView *)tab ...
- UITableView、UICollectionView行高/尺寸自适应
UITableView 我们都知道UITableView从iOS 8开始实现行高的自适应相对比较简单,首先必须设置estimatedRowHeight给出预估高度,设置rowHeight为UITabl ...
- iOS开发tips-UITableView、UICollectionView行高/尺寸自适应
UITableView 我们都知道UITableView从iOS 8开始实现行高的自适应相对比较简单,首先必须设置estimatedRowHeight给出预估高度,设置rowHeight为UITabl ...
- 20180428 xlVBA自动设置成绩条行高
'自动设置行高 传入工作表Sht 和 每页打印的行数RowsInOnePage Public Sub AutoSetRowHeight(ByVal Sht As Worksheet, Optional ...
- POI精确设置Excel的行高和列宽
EXCEL的行高度和列宽度单位是不一样的. 1,EXCEL列高度的单位是磅,Apache POI的行高度单位是缇(twip): 1英寸=72磅=25.4毫米=1440缇1磅=0.353毫米=20缇 P ...
- UITableView!别再用代码计算行高了(一)
你还在用代码去计算行高吗?你不感觉那种方式很low吗?从今天起,试着做些改变吧! 别给我讲你喜欢写代码的感觉,你就是要用代码去计算行高,那我这篇文章不适合你. 在讲解复杂内容之前,还是先学习简单的内容 ...
随机推荐
- err:LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLE
err:LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLE err:LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLE err:LIBUSB_S ...
- Zabbix Agent 安装指南和 Zabbix Server 设置自动发现
Zabbix Agent分为两种模式,被动模式(Passive)和主动模式( 我们实验在node1.yulongjun.com 和node2.yulongjun.com上分别配置Zabbix Agen ...
- Centos7网卡配置命令nmcli
在配置Centos6时,大家第一想到的就是把networkManager这个服务关掉,让它消失,这个服务台太鸡肋了,不该起作用的时候经常起作用,给管理带来了不便,但是在Centos7当中network ...
- 【模板】多标记 LCT
代码如下 #include <bits/stdc++.h> using namespace std; typedef long long LL; const int mod = 51061 ...
- Winforms界面开发DevExpress v19.2:图表、编辑器功能增强
DevExpress Winforms Controls 内置140多个UI控件和库,完美构建流畅.美观且易于使用的应用程序.无论是Office风格的界面,还是分析处理大批量的业务数据,DevExpr ...
- 访问node后端接口示例(入门)
一.基础安装参考我的另一篇随笔 https://www.cnblogs.com/zhuxingqing/p/11526558.html 另在之前的基础上引入了jquery,方便使用ajax 二.前端代 ...
- java mybaits 调用存储过程
@Override public BaseResultMessage saveOrderConfirm(String billNo) { BaseResultMessage rm = Utils.re ...
- this 的用法 为原始类型扩展方法
namespace Demo { public static class Extends { // string类型扩展ToJson方法 public static object ToJson(thi ...
- js中Array的sort方法
Array.sort方法里需要传入一个参数,是一个function, 如果想要升序排序,就传入这样的一个function: function sortFunction(a,b){ return a-b ...
- linux下ssh免秘钥登录
1.检查防火墙是否关闭 (1)切换到root用户 (2)查看防火墙状态 service iptables status 这是没有关闭 (3)设置关闭 service iptables stop 2.检 ...