今天在写创建一个UItableviewcontroller的时候遇到了Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]的断言报错信息,试了各种方法都没解决问题之后,终于在论坛上找到了解决方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString * cellId=@"BaseCell";
static BOOL nibsRegistered = NO;
if(!nibsRegistered)
{
UINib *nib = [UINib nibWithNibName:@"BaseCellTableViewCell" bundle:nil];
[tableView registerNib:nib forCellReuseIdentifier:cellId];
nibsRegistered = YES;
}
BaseCellTableViewCell * cell=(BaseCellTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:cellId];
cell.NameLabel.text=@"xxx商城";
cell.PhoneLabel.text=@"12345678";
cell.PhoneLabel.font=[UIFont systemFontOfSize:12];
cell.CellImageView.image=[UIImage imageNamed:@"test1.png"];
[cell setLocationLabel:cell.LocationLabel];
[cell setIcon2Image:cell.icon2Image];
[cell setIcon1Image:cell.icon1Image];
cell.selected=YES;
return cell;
}原因暂时只知道是注册cell的问题,还没有找到具体的答案,以后自定义的cell尽量中这种方式生成
本文介绍了一种在UITableView中遇到的断言失败问题的具体解决方案,通过注册单元格的方式避免了Assertion failure in -[UITableView configureCellForDisplay:forIndexPath:]错误的发生。

2万+

被折叠的 条评论
为什么被折叠?



