Question

- (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;
 }

I get warning while analyzing project like this "value stored to 'cell' is never read" .Well! code is using the cell but outside of that if block. I want to silent this warning!

Can anybody help me for this?

Thanks in advance :)

Was it helpful?

Solution

The problem here:

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]; 
   } 

You initialize the cell from custom class, and then you assigned to the cell from a nib, so that you lose control of the first cell and you have not used the first cell.

Try this:

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;
        }
    }
}

or:

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

or:

if (!cell){
    cell = [[[ThreePartitionCells alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:customCell_Identifierr] autorelease];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top