2012-11-13 60 views
1

我有兩個自定義單元格的表,當嘗試出列時崩潰。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 
} 

的其他細胞是一樣的

+0

請查看本使用電池串directl沒有cellIdentifier變量。 –

+0

沒有這樣工作也 –

回答

0

你可能有問題代碼 !這是如果數組沒有請求的索引?

只是讓你的支票這樣

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

您正在使用poetCell.Name。你能確定你的自定義單元格有一個「Name」屬性(在你的自定義單元格的.h/.m中)嗎?我認爲問題來自這裏。順便說一下,如果您的自定義單元格確實具有此屬性,則應將其更改爲name而不是Name。變量在開始時用大寫字母表示類名。變量始終應以小寫字母開頭。

你也應該發佈你的自定義單元的代碼。


編輯:

正如在這裏看到:Class is not key value coding-compliant

在Interface Builder你從文件的所有者聯繫您IBOutlets時,你應該從小區視圖鏈接它們。

你能檢查嗎?

+0

沒有問題 –

+0

你可以給我們你的自定義單元的代碼?你怎麼能確定它來自線* poetCell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; *?你可以在下一行放置一個斷點,看看它是否到達它? – rdurand

+0

我知道因爲它沒有達到當然的下一行:) –

0

假設你的目標的iOS5 +,你有沒有包括像在viewDidLoad中的以下內容:

[self.tableView registerNib:[UINib nibWithNibName:kStandardCellIdentifier bundle:nil] forCellReuseIdentifier:(NSString *)] 
相關問題