*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DJLZTableViewCell TianNumberLabel]: unrecognized selector sent to instance 0x7fafbd083e00'

在列表tableView里面的- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath中,对使用xib制作的cell的label赋值出现这个错误,我一看,这是这个方法不能识别,但是我看了我的cell的.h里面是有这个控件的,最后我对比了另外一个通用这样写的模板,发现问题了

[_tableView registerNib:[UINib nibWithNibName:@"DJLZTableViewCell" bundle:nil] forCellReuseIdentifier:@"reuseIdentifier"];
DJTaTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseIdentifier" forIndexPath:indexPath];

if (!cell) {
    
    cell = [[DJTaTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"reuseIdentifier"];
}

这里的3个名称不是一样的,我复制过来的代码没有改全,[_tableView registerNib:[UINib nibWithNibName:@"DJTaTableViewCell" bundle:nil] forCellReuseIdentifier:@"reuseIdentifier"]; 这里双引号里面的东西没有改过来,这样就正常了

附:朋友建议:

如果是storyboard添加cell的情况

Storyboard:

(UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ID"];
cell.model = self.dataArray[indexPath.row];
// 如果是自定义的Cell需要加自己的delegate
//cell.delegate = self;
return cell;
}

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

推荐阅读更多精彩内容

  • 版权声明:未经本人允许,禁止转载. 1. TableView初始化 1.UITableView有两种风格:UITa...
    萧雪痕阅读 7,896评论 2 10
  • 《iOS 列表性能优化之异步绘制[https://mp.weixin.qq.com/s/AX-WY2HalDKE6...
    goyohol阅读 2,047评论 0 1
  • UITableView UITableView内置了两种样式:UITableViewStylePlain,UITa...
    _凌浩雨阅读 4,187评论 0 1
  • 首先创建4个控制器oneViewController,twoViewController,threeViewCon...
    老公123阅读 3,047评论 0 0
  • 齐牛妈打包好了寄往未来的物品,包括牛宝小时候穿过的衣服玩具,刚上学时的书本,胎毛,还有部分成长视频的照片以及和牛爸...
    采岚阅读 1,046评论 0 0