*** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/C

来源:互联网 发布:vb.net 开发工具 编辑:程序博客网 时间:2024/06/18 09:31
使用UITableView出现

*** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/UITableView.m:7971的解决方法。

1.可能是把return Cell;放在了if语句内如下所示:

{        static NSString *CellIdentifier1 = @"hotCell";        HotCity_Cell *hotCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];        if (hotCell == nil)        {            hotCell = [[HotCity_Cell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];            hotCell.backgroundColor = [UIColor clearColor];            return hotCell;// 把return 语句写在这里        }//        return hotCell;// return 语句应该写在这里}

2.没有判断cell 为空值,应该像上面的代码一样,有If语句来判断cell是否为空。错误的写法如下:

{        static NSString *CellIdentifier1 = @"hotCell";        HotCity_Cell *hotCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];        hotCell = [[HotCity_Cell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];        hotCell.backgroundColor = [UIColor clearColor];        return hotCell;}

下面是初始化celll的正确方法:

{        static NSString *CellIdentifier1 = @"hotCell";        HotCity_Cell *hotCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];        if (!hotCell)        {            hotCell = [[HotCity_Cell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1];            hotCell.backgroundColor = [UIColor clearColor];        }        return hotCell;}


1 0