Custom UITableViewCell changing indexPath While Scrolling ?
        Posted  
        
            by Chris
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Chris
        
        
        
        Published on 2010-04-22T02:10:07Z
        Indexed on 
            2010/04/22
            2:13 UTC
        
        
        Read the original article
        Hit count: 462
        
I have a custom UITableViewCell which I created in Interface Builder. I am successfully Dequeuing cells, but as I scroll, the cells appear to begin calling different indexPaths. In this example, I am feeding the current indexPath.section and indexPath.row into the customCellLabel. As I scroll the table up and down, some of the cells will change. The numbers can be all over the place, but the cells are not skipping around visually.
If I comment out the if(cell==nil), then the problem goes away.
If I use a standard cell, the problem goes away.
Ideas why this might be happening?
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"CalendarEventCell"];
    if (cell == nil) {
        NSLog(@"Creating New Cell !!!!!");
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CalendarEventCell" owner:self options:nil];
        cell = (UITableViewCell *)[nib objectAtIndex:0];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
   // Set up the cell...
  [customCellLabel setText:[NSString stringWithFormat:@"%d - %d",indexPath.section, indexPath.row]];
    return cell;
}
© Stack Overflow or respective owner