zoukankan      html  css  js  c++  java
  • 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. }  
  • 相关阅读:
    深入剖析.NET运行机制
    在浏览器地址中加参数
    mysql 中文乱码
    今天在看一些面试题的时候遇到的一个关于strcmp()返回值的细节问题
    如何在学习过程中统一IDE的编码!
    通过文件方式,在文件内容开头写入字符串!
    Java编写圆的相关计算
    leetcode 上的Counting Bits 总结
    cocos2dx打包apk
    CEGUI0.8.4例子
  • 原文地址:https://www.cnblogs.com/dhcn/p/7130904.html
Copyright © 2011-2022 走看看