tableView:dequeueReusableCellWithIdentifier:和tableView: dequeueReusableCellWithIdentifier: forIndexPath:

如果既没有在TableViewController中使用代码的方式注册:

[self.tableView registerClass: [CustomTableViewCell class] 
forCellReuseIdentifier: CellTableIdentifier];

也没有在storyboard或nib中的视图Cell的Identity Inspector->Custom Class对应Cell:

identity inspector

实现tableView:cellForRowAtIndexPath:时,调用以下方法会在运行时报错:
*** Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'***

......
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
@"Cell" forIndexPath:indexPath];
......

这时应该采用没有IndexPath参数这种:

......
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
@"Cell"];

if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:
UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    }
......
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容