1

我有一个带有两个自定义单元格的表格,当尝试出队时它们会崩溃。

这是代码:

int row = indexPath.row;

static NSString *CellIdentifier;
UITableViewCell* cell;
PoetCell * poetCell;
PoemsCell * poemsCell;

if(row == 0) {

    CellIdentifier = @"PoetCell";

} else {

    CellIdentifier = @"poemsCell";        
}

if(row == 0) {

    poetCell= [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    poetCell.image.image=[UIImage imageWithData:imageData];

    if([imageData length]==0){

        poetCell.image.hidden=TRUE;
        poetCell.Name.frame=CGRectMake(124, poetCell.Name.frame.origin.y, poetCell.Name.frame.size.width, poetCell.Name.frame.size.height);

    } else {

        poetCell.Name.frame=CGRectMake(38, poetCell.Name.frame.origin.y, poetCell.Name.frame.size.width, poetCell.Name.frame.size.height);

    }

    poetCell.desc.text=pdesc;
    poetCell.Name.text=pName;

} else {

        poemsCell= [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if([poemsNames count]) {
            poemsCell.poemText.text=[poemsNames objectAtIndex:row-1];
        }
}

它在线上给出错误:

poetCell= [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];

哪个说

[UITableViewCell setValue:forUndefinedKey:]:这个类不符合键名的键值编码。

我知道当笔尖中的链接错误时会出现此错误。但我认为代码中的情况并非如此。所以任何人都可以得到问题所在吗?

已编辑

我认为整个问题在于初始化poetCell和poescesCell,这就是代码

#import <UIKit/UIKit.h>

@interface PoetCell : UITableViewCell
{
    IBOutlet UILabel*Name;
    IBOutlet UILabel*desc;
    IBOutlet UIImageView*image;
}
@property(nonatomic,retain)IBOutlet UILabel*Name;
@property(nonatomic,retain)IBOutlet UILabel*desc;
@property(nonatomic,retain)IBOutlet UIImageView*image;

@end

#import "PoetCell.h"

@implementation PoetCell
@synthesize Name,desc,image;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

另一个单元格是一样的

4

3 回答 3

0

您正在使用poetCell.Name. 您能否确保您的自定义单元格具有“名称”属性(在您的自定义单元格的 .h/.m 中)?我认为问题来自这里。

顺便说一句,如果您的自定义单元格确实具有此属性,则应将其更改为name而不是Name. 以大写字母开头的变量用于类名。变量应始终以小写字母开头。

您也应该发布自定义单元格的代码。


编辑 :

如此处所示:类不符合键值编码

在界面构建器中,当您应该从单元格视图链接它们时,您从文件所有者链接了您的 IBOutlets。

你能检查一下吗?

于 2012-11-13T10:50:40.307 回答
0

假设您的目标是 iOS5+,您是否在 viewDidLoad 中包含以下内容:

[self.tableView registerNib:[UINib nibWithNibName:kStandardCellIdentifier bundle:nil] forCellReuseIdentifier:(NSString *)]
于 2012-11-15T00:07:35.260 回答
0

你的代码可能有问题!如果数组没有请求的索引?

像这样做你的支票

    if([poemsNames count] > row  ){
        poemsCell.poemText.text=[poemsNames objectAtIndex:row-1];
    } 
于 2012-11-13T10:35:56.397 回答