2010-10-15 62 views
5

我正嘗試使用我在IB中構建的單元格來構建自定義表格視圖。我收到一個奇怪的錯誤:自定義UITableViewCell錯誤

<BroadcastViewController 0x4b4f5f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key postText. 

在IB中,一切都正確連接到單元控制器。不知道爲什麼會發生這種情況。

這是我的cellForRowAtIndexPath是什麼樣子:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

//Get the folder object of interest 
Broadcast *messageAtIndex = [self.messages objectAtIndex:indexPath.row] ; 

static NSString *CellIdentifier = @"BroadcastTableViewCell"; 
static NSString *CellNib = @"BroadcastTableViewCell"; 

BroadcastTableViewCell *cell = (BroadcastTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    //ERRORING ON THIS LINE... 
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil]; 
    cell = (BroadcastTableViewCell *)[nib objectAtIndex:0]; 
} 


cell.postText.text = messageAtIndex.replyText; 
cell.authorName.text = messageAtIndex.postCreatorFirstName; 
cell.postDate.text = messageAtIndex.creationDate; 

return cell; 

} 

沒有人見過這種類型的錯誤?如果您需要更多信息,請告知我...

+0

需要功能的完整代碼cellForRowAtIndexPath – SegFault 2010-10-15 14:17:31

+0

已更新。 – gabaum10 2010-10-15 14:23:00

+0

看起來你試圖爲'postText'插入一個不是NSDictionary的東西? :) – willcodejavaforfood 2010-10-15 14:25:28

回答

5

什麼是真正奇怪的是,它抱怨該類BroadcastViewController不KVC符合postText

就我所見,postText是您的單元格中的標籤,因此IBOutlet應該在BroadcastTableViewCell類中。因此,請查看您在IB中鏈接postText標籤的位置。另外,它可能是因爲你在這個標籤的視圖控制器中有一個IBOutlet,你已經刪除了它,但是你忘了刪除IB中的鏈接。無論如何,有一個地方是你的問題。事實上你在那條線上有錯誤,只是因爲它在那裏加載你的NIB,它與單元本身或者與所有者沒有任何關係。

+0

好吧,我已經檢查並重新檢查了IB連接。在BroadcastTableViewCell類中,一切都已正確連接。沒有與其他任何視圖控制器的連接。它確實沒有任何意義。 – gabaum10 2010-10-15 15:27:07

+0

你明白了。這是在筆尖的東西。謝謝:) – gabaum10 2010-10-15 15:37:29

1

可能與dequeueReusableCellWithIdentifier返回UITableViewCell *有關。

我normaly做:

UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier... 
CustomCell* acell = (CustomCell*)cell; 

設置所有者爲零。

NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:nil options:nil]; 
+0

好吧,我看到如何鑄造這將是一個好主意,但這仍然沒有幫助的初始負載,當第一個單元格爲零。需要處理一些事情:「if(cell == nil)」 – gabaum10 2010-10-15 14:33:28

+0

看過之後,這與我現在所做的幾乎完全一致,只是將它放在一個更長的方式... – gabaum10 2010-10-15 14:40:14

+0

NSArray * nib = [[NSBundle mainBundle] loadNibNamed:CellNib所有者:無選項:無];將所有者設置爲零。 – 2010-10-15 14:41:02

1

好吧,算了一下。 IB中的連接確實不正確。我讓它們鏈接到文件的所有者,而不是實際的對象。我也會給這個Stelian,因爲他指示我檢查筆尖。感謝你的幫助!