setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key

http://blog.csdn.NET/h3c4lenovo/article/details/8556887

 

 

今天在写自定义UITableViewCell的时候遇到一个Crash,特别无语,折腾了大半天,终于解决了。

Bug如下:

 

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x8a4b500> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key strss.'


先说解决办法吧:

 

 

然后讲故事:

1.如何使用IOS UITableView?

参考:http://blog.csdn.NET/h3c4lenovo/article/details/8307253

 

2.如何使用自定义的UITableViewCell实现UITableView?

参考:http://www.howzhi.com/group/iosDevelop/discuss/2068

 

3.单独创建的xib/nib文件如何与.h/.m文件关联起来?

定义xib中File's Owner 或 View的Custom Class 如上图所示。注:网上大部分说报错的原因要么就是存在无效的连接,或者File's Owner的custom class没有连接。

 

4.代码中如何引用自定义的TableViewCell?

 

[cpp]  view plain  copy
 
 
    1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  
    2. {  
    3.     static NSString *CustomCellIdentifier = @"testCellIdentifier";  
    4.       
    5.     static BOOL nibsRegistered = NO;  
    6.     if (!nibsRegistered) {  
    7.         UINib *nib = [UINib nibWithNibName:@"testCell" bundle:nil];  
    8.         [tableView registerNib:nib forCellReuseIdentifier:CustomCellIdentifier];  
    9.         nibsRegistered = YES;  
    10.     }  
    11.       
    12.     testCell *cell = [tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier];  
    13.   
    14.     [cell setMyText:@"xxx"];  
    15.       
    16.     return cell;  
    17. }  

转载于:https://www.cnblogs.com/dhcn/p/7130904.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值