美文网首页
failed to obtain a cell from its

failed to obtain a cell from its

作者: sttech | 来源:发表于2017-06-07 16:43 被阅读0次
    错误类型

    错误原因分析

    • 是因为你的cell被调用的早了。先循环使用了cell,后又创建cell。顺序错了。

    解决办法

    • 方法一
    @interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
    {
        UINib * nib;
    }
    @end
    
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        static NSString * cellIdentifier = @"GameTableViewCell";
        
        if (nib == nil) {
            nib = [UINib nibWithNibName:@"GameTableViewCell" bundle:nil];
            [tableView registerNib:nib forCellReuseIdentifier:cellIdentifier];
            NSLog(@"我是从nib过来的");
        }
        GameTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        return cell;
    } 
    
    • 方法2 调整代码顺序
      尤其需要注意tableView的注册cell的方法

    相关文章

      网友评论

          本文标题:failed to obtain a cell from its

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