我有兩個自定義單元格的表,當嘗試出列時崩潰。ios:UITableViewCell與故事板中的自定義單元格崩潰
下面是代碼:
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和poemsCell的初始化這是是代碼
#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
}
的其他細胞是一樣的
請查看本使用電池串directl沒有cellIdentifier變量。 –
沒有這樣工作也 –