failed to obtain a cell from its dataSource

failed to obtain a cell from its dataSource_第1张图片
错误类型

错误原因分析

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

解决办法

  • 方法一
@interface ViewController ()
{
    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 dataSource)