2012-01-30 114 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