Note that there are some explanatory texts on larger screens.

plurals
  1. POCell reuse issue for custom table view cell
    primarykey
    data
    text
    <p>I've created a feature in my app that loads a custom cell when tapping the cell. tapping the cell will show the extra buttons and tapping again will hide it, no problem with that. however, I think I have a cell reuse issue here when tapping rows next to the currently selected row. look at the screenshot, I tap North California then the buttons show up, when I tap Ethiopia the result is the second screenshot.</p> <p><a href="http://i228.photobucket.com/albums/ee262/romano2717/reuse.jpg" rel="nofollow">http://i228.photobucket.com/albums/ee262/romano2717/reuse.jpg</a></p> <p>here's the code</p> <pre><code> if(selectedIndexPath != nil &amp;&amp; [selectedIndexPath isEqual:indexPath]) { selectedIndex = indexPath.row; NSLog(@"selectedIndex %d",selectedIndex); static NSString *CustomCellIdentifier = @"CustomCell"; CustomCell *customCell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier]; if (customCell == nil) { customCell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CustomCellIdentifier] autorelease]; } customCell.locationLabelOutlet.text = [usgsFeeds objectAtIndex:[indexPath row]]; customCell.dateLabelOutlet.text = [pubDateArr objectAtIndex:[indexPath row]]; float thisMag; thisMag = [(NSNumber *)[magnitudeArr objectAtIndex:[indexPath row]] floatValue]; customCell.magnitudeImageOutlet.image = [self imageForMagnitude:thisMag]; [customCell setSelectionStyle:UITableViewCellSelectionStyleNone]; return customCell; } else{ static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; locationLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10, 3, 225, 20)] autorelease]; locationLabel.tag = kLocationLabelTag; locationLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0]; locationLabel.backgroundColor = [UIColor clearColor]; [cell.contentView addSubview:locationLabel]; //same as above will follow } else{ locationLabel = (UILabel *)[cell.contentView viewWithTag:kLocationLabelTag]; dateLabel = (UILabel *)[cell.contentView viewWithTag:kDateLabelTag]; magnitudeImage = (UIImageView *)[cell.contentView viewWithTag:kMagnitudeImgTag]; } locationLabel.text = [usgsFeeds objectAtIndex:[indexPath row]]; dateLabel.text = [pubDateArr objectAtIndex:[indexPath row]]; float thisMag; thisMag = [(NSNumber *)[magnitudeArr objectAtIndex:[indexPath row]] floatValue]; magnitudeImage.image = [self imageForMagnitude:thisMag]; return cell; } </code></pre> <p>and this is my custom cell</p> <pre><code> - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier: (NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { locationLabelOutlet = [[UILabel alloc] initWithFrame:CGRectMake(10, 3, 210, 17)]; locationLabelOutlet.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0]; locationLabelOutlet.backgroundColor = [UIColor clearColor]; //and other outlets [thisContainer addSubview:locationLabelOutlet]; [thisContainer addSubview:magnitudeImageOutlet]; [thisContainer addSubview:dateLabelOutlet]; [buttonsView addSubview:locButton]; [buttonsView addSubview:detButton]; [buttonsView addSubview:shabutton]; [buttonsView addSubview:favButton]; [thisContainer addSubview:buttonsView]; [self.contentView addSubview:thisContainer]; </code></pre> <p>this is for the did select</p> <pre><code> - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:NO]; selectedIndexPath = indexPath; if(selectedIndex == indexPath.row) { selectedIndexPath = nil; [tableView reloadRowsAtIndexPaths: [NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; selectedIndex = -1; return; } if(selectedIndexPath != nil &amp;&amp; [selectedIndexPath isEqual:indexPath]) { [tableView reloadRowsAtIndexPaths: [NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload