自定义UITableViewCell子类:此类不是符合编码规范的键值 [英] Custom UITableViewCell subclass: This class is not a key value coding-compliant

查看:111
本文介绍了自定义UITableViewCell子类:此类不是符合编码规范的键值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在stackoverflow中查看了几乎所有关于此问题的相关问题并尝试了所有可能的解决方案,但我仍然无法弄清楚为什么会出现此错误:

I've looked at almost all of the related questions about this here in stackoverflow and tried all their possible solutions but I still can't figure out why I get this error:

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

我正在尝试使用nibname加载自定义表格视图单元格:@CustomCell。它的类被分配给CustomCell(与nib名称相同的类名)。它的文件所有者也被设置为加载这个单元格的类 - ProductsTableViewControllerWithSearch。笔尖中的所有插座都连接到CustomCell.m中的插座

I'm trying to load a customized table view cell with the nibname: @"CustomCell". Its class is assigned to "CustomCell" (same class name as the nib name). Its file's owner is also set to the class which loads this cells - "ProductsTableViewControllerWithSearch". All the outlets in the nib are connected to the ones in CustomCell.m

这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellClassName = @"CustomCell";
    static NSString *CellIdentifier = @"Custom Items Cell";

    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {

      NSArray *topLevelItems =  [[UINib nibWithNibName:CellClassName bundle:[NSBundle mainBundle]] instantiateWithOwner:self options:nil];
        cell = [topLevelItems objectAtIndex:0];

    }
//... more irrelevant code here
}

请有人帮助我。我已经工作了4个多小时。非常感谢!

Can somebody help me please. I've been working on this for more than 4 hours. Thanks a lot!

PS:我正在使用ARC并正在为iOS 5开发。

PS: I'm using ARC and am developing for iOS 5.

这是我的CustomCell.h。

Here's my CustomCell.h.

#import <UIKit/UIKit.h>

@interface CustomCell : UITableViewCell{
    UILabel *textLabel;
    UILabel *detailTextLabel;
    UIButton *starButton;
}

@property (strong, nonatomic) IBOutlet UILabel *textLabel;
@property (strong, nonatomic) IBOutlet UILabel *detailTextLabel;
@property (strong, nonatomic) IBOutlet UIButton *starButton;

@end

我的CustomCell.m中没有任何内容

There's nothing in my CustomCell.m

推荐答案

在Interface Builder中,您需要将单元格的类设置为CustomCell,而CustomCell需要具有属性 title

In Interface Builder you need to set the class of the cell to CustomCell and CustomCell needs to have a property title.


此类不是密钥值编码兼容的密钥...

通常意味着在类上找不到属性,Interface Builder正在尝试使用该属性,从而导致在崩溃中。

Usually means that a property is not found on a class and Interface Builder is trying to use that property, resulting in a crash.

这篇关于自定义UITableViewCell子类:此类不是符合编码规范的键值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆