2012-01-30 115 views
0

我想使用自定義tableview Cell。自定義tableviewcell錯誤

我有productTableViewCell類。在我的xib中,我定義了一個lblProduct,在這個標籤上我想展示我的產品名稱。我已經合成它,並在我的xib中正確連接它。

現在在我的其他班與我的tableview在裏面。我這樣做。我所有的產品都在arrayProducts中。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    productTableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 

     NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"productTableviewCell" owner:nil options:nil]; 

     for (UIView *view in views) { 
      if([view isKindOfClass:[UITableViewCell class]]) 
      { 
       cell = (productTableviewCell*)view; 
      } 
     } 
    } 
    NSString *cellValue = [arrayProducts objectAtIndex:indexPath.row]; 
    NSLog(@"value: %@", cellValue); 
    cell.lblProduct.text = cellValue; 

    // NSDictionary *info = [json objectAtIndex:indexPath.row]; 
    //cell.lblProduct.text = [info objectForKey:@"Pro_naam"]; 

    return cell; 

} 

但是當我運行它。我得到這個錯誤。

2012-01-30 10:02:40.032 MamzelBestelling2 [12923:F803] *終止 應用由於未捕獲的異常 'NSUnknownKeyException',原因: 「[setValue方法:forUndefinedKey:]:這個類是不 關鍵值符合密鑰lblProduct。「 *第一擲調用堆棧:(0x13c0052 0x1551d0a 0x13bff11 0x9b7032 0x928f7b 0x928eeb 0x943d60 0x23691a 0x13c1e1a 0x132b821 0x23546e 0x237010 0x4d9f 0xb0e0f 0xb1589 0x9cdfd 0xab851 0x56301 0x13c1e72 0x1d6a92d 0x1d74827 0x1cfafa7 0x1cfcea6 0x1cfc580 0x13949ce 0x132b670 0x12f74f6 0x12f6db4 0x12f6ccb 0x12a9879 0x12a993e 0x17a9b 0x2148 0x20a5)終止叫拋出異常當前語言:auto; 當前客觀-c(gdb)

任何人都可以提供幫助嗎?

回答

0

你並不需要首先將它存儲到NSString中。嘗試做這種方式:

cell.lblProduct.text = [arrayProducts objectAtIndex:indexPath.row]; 

還要確保你已經完成了@property@synthesize正確,並在您CustomCell廈門國際銀行連接起來

+0

我發現這個問題。我的自定義tableview單元格中有一個錯誤的標識符:) – steaphann 2012-01-30 12:29:46

0

如果創建CustomTableViewCell,你必須設定「標籤lblProduct」,說100然後 做

UILabel *label=(UILabel *)[cell viewWithTag:100]; 
NSString *cellValue = [arrayProducts objectAtIndex:indexPath.row]; 
NSLog(@"value: %@", cellValue); 
lblProduct.text = cellValue; 

return cell; 

它將工作!!!!

欲瞭解更多信息http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW1