美文网首页
8.解决 Assertion failure in -[UITa

8.解决 Assertion failure in -[UITa

作者: Matt_Z_ | 来源:发表于2017-05-19 11:30 被阅读0次
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 -[UITa

      本文链接:https://www.haomeiwen.com/subject/mzqyxxtx.html