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

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;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容