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. }  
  • 相关阅读:
    数论笔记
    哈哈哈
    闭关修炼屯题中,期末考完A
    acm几何
    POJ
    Educational Codeforces Round 42 (Rated for Div. 2) D.Merge Equals (优先队列)
    Educational Codeforces Round 42 (Rated for Div. 2) C. Make a Square (dfs)
    牛客网 VVQ 与线段 (优先队列或线段树或RMQ)
    Educational Codeforces Round 41 (Rated for Div. 2) C.Chessboard (DP)
    Educational Codeforces Round 41 (Rated for Div. 2)D. Pair Of Lines
  • 原文地址:https://www.cnblogs.com/dhcn/p/7130904.html
Copyright © 2011-2022 走看看