解决 Assertion failure in -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] crash的方法

当遇到类似这样的问题时,大多情况是我们的代码中可能有取图片宽高后做等比例处理时,正常情况下图片是存在的,但当图片不存在而我们又用了图片的宽做分母取得占位符

位置相应的高时就会取到一个无限大的值,这时取到的返回值为: nam 造成程序crash掉:

在tableview的heightForRow方法里返回的数据错误,返回的数据是nan型的,为什么是nan呢,猜测可能是数据越界,你可能得到到的是double类型,而heightforrow需要的是CGFloat类型

*** Assertion failure in -[UISectionRowData refreshWithSection:tableView:tableViewRowData:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UITableViewRowData.m:619

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'table view row height must not be negative - provided height for index path (<UIMutableIndexPath 0x7fc9a368f0b0> 2 indexes [0, 0]) is nan'


1.在heightforrow方法里 做出判断
return (!isnan([LDCompanyDynamicCellgetCellHeight]))?[LDCompanyDynamicCellgetCellHeight]:70;
1在数据原始处修改,

+(CGFloat)getCellHeight:(LDCompanyModel *)company{
    CGFloat intervalY = 5.0;
    CGFloat y;
     y+=55+intervalY;
     if (company.industry) {
        CGSize industrySize = [company.industry sizeWithFont:[UIFont systemFontOfSize:12.0] constrainedToSize:CGSizeMake([UIScreen mainScreen].bounds.size.width-76-10, CGFLOAT_MAX) lineBreakMode:NSLineBreakByWordWrapping];
        y+=floor(industrySize.height)+intervalY;
    }else{
        y+=intervalY;
   }
    NSLog(@"y1-----%f",y);
    y=floor(y);
    NSLog(@"y2-----%f",y);
    return y;
}
这是获取cell高度,打印的数据
2014-10-09 18:58:39.661 LiuDuSpace[7090:248073] y1-----79.000000
2014-10-09 18:58:39.661 LiuDuSpace[7090:248073] y2-----79.000000
2014-10-09 18:59:36.842 LiuDuSpace[7090:248073] y1-----nan
2014-10-09 18:59:36.842 LiuDuSpace[7090:248073] y2-----nan



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值