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

    static NSString *customCell_Identifier = @"CustomCell";
    ThreePartitionCells *cell = (ThreePartitionCells *)[tableView dequeueReusableCellWithIdentifier:customCell_Identifier];

    if (cell == nil)
   {
      cell = (ThreePartitionCells *)[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:customCell_Identifier] autorelease];
      NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ThreePartitionCells" owner:self options:nil];
      cell =  [nib objectAtIndex:0];
   }

  [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
   NSLog(@"%@", [arrActivityList objectAtIndex:[indexPath row]]);

   NSString *strTemp = [NSString stringWithFormat:@"%@-%@", [[[[[arrActivityList objectAtIndex:[indexPath row]] objectForKey:@"ITEMS"] objectForKey:@"Area"] objectForKey:@"AREANAME"] objectForKey:@"text"], [[[[[[[arrActivityList objectAtIndex:[indexPath row]] objectForKey:@"ITEMS"] objectForKey:@"Area"] objectForKey:@"ITEMS"] objectForKey:@"Bin"] objectForKey:@"BIN_BARCODE"] objectForKey:@"text"]  ];

  cell.lblProductName.text = strTemp;
  cell.lblExpectedCount.text = [[[arrActivityList objectAtIndex:[indexPath row]]objectForKey:@"ProductName"]objectForKey:@"text" ];

  cell.lblCounted.text = [[[arrActivityList objectAtIndex:[indexPath row]] objectForKey:@"Status"] objectForKey:@"text"];

  [cell.lblProductName setFont:[UIFont fontWithName:@"Helvetica" size:13.0]];
  [cell.lblCounted setFont:[UIFont fontWithName:@"Helvetica" size:13.0]];

  return cell;
 }



有人可以帮我吗?

提前致谢 :)

最佳答案

这里的问题:

if (cell == nil)
   {
  cell = (ThreePartitionCells *)[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:customCell_Identifier] autorelease];

  NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ThreePartitionCells" owner:self options:nil];

  cell =  [nib objectAtIndex:0];
   }

您从自定义类初始化单元格,然后从笔尖将其分配给该单元格,这样您就失去了对第一个单元格的控制,并且尚未使用第一个单元格。

尝试这个:
if (!cell){
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ThreePartitionCells"
                                                 owner:self
                                               options:nil];
    for (id obj in nib) {
        if ([obj isKindOfClass:[ThreePartitionCells class]]) {
            cell = (ThreePartitionCells *)obj;
            break;
        }
    }
}

要么:
if (!cell){
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ThreePartitionCells"
                                                 owner:self
                                               options:nil];
    cell = nib[0];
}

要么:
if (!cell){
    cell = [[[ThreePartitionCells alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:customCell_Identifierr] autorelease];
}

关于objective-c - 永远不会读取存储在 'cell'中的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19900725/

10-15 17:52