8.解决 Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]错误

8.解决 Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]错误_第1张图片
screenshot.png

出现这种错误,应该检查cell返回的值是否为空。

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //出现错误的原因就是因为这个cell为nil了
    UITableViewCell *cell;
    return cell;
}

解决方案:当cell为nil时做相应的操作

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell;
    //添加了下面的代码就不会出现上面的问题,对cell为nil的情况作出判断,如果为空,做相应的操作
    if(cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell_id"];

    }
    return cell;
}

你可能感兴趣的:(8.解决 Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]错误)