您的位置:首页 > 产品设计 > UI/UE

报错:*** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Librar

2016-05-31 07:48 447 查看
报错:* Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/C

使用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;
}


文章来源:http://m.blog.csdn.net/article/details?id=51028141
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: