我有一个带有两个自定义单元格的表格,当尝试出队时它们会崩溃。
这是代码:
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
}
另一个单元格是一样的