Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableView scrolling changess image inside UITableViewCell
    primarykey
    data
    text
    <p>I am displaying some data using a <code>UITableViewController</code>, my table has 2 static sections with 6 static rows each. And I am subclassing <code>UITableViewCell</code> in order to add 3 Labels and a View, in the view I draw an arrow in only one of the cells in one of the sections.</p> <p>This all goes perfectly fine. Till i scroll down... then the arrow is randomly placed in other cells, once i scroll back up the arrow has again changed cells... This also happens if i try to set a <code>backgroundColor</code> for only one of the cells. Once I scroll down and up the cell that originally had the color no longer has it, and another seemingly random cell has the color now.</p> <p>Here is some of my code:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; TableViewCells *cell = (TableViewCells *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[TableViewCells alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } [self configureCell:cell atIndexPath:indexPath]; return cell; </code></pre> <p>}</p> <pre><code>- (void)configureCell:(TableViewCells *)cell atIndexPath:(NSIndexPath *)indexPath { switch (indexPath.row) { case 0: { if (indexPath.section == cotizacionIdeal) { cell.arrowImage = [UIImage imageNamed:@"arrowUp.png"]; [cell.nombre setText:@"Recursos"]; [cell.cantidad setText:[NSString stringWithFormat:@"%1.2f", [cotizacionPrevia.sueldoDeRecursos doubleValue]]]; [cell.porcentaje setText:[NSString stringWithFormat:@"%1.2f%@", [cotizacion.recursosPorcentaje doubleValue], @"%"]]; } else { [cell.nombre setText:@"Recursos"]; [cell.cantidad setText:[NSString stringWithFormat:@"%1.2f", [cotizacionPrevia.sueldoDeRecursos doubleValue]]]; [cell.porcentaje setText:[Calculate calcPorcentaje:cotizacionPrevia.sueldoDeRecursos totalReal:self.totalReal]]; } } break; case 1: { if (indexPath.section == cotizacionIdeal) { [cell.nombre setText:@"Comision de Venta"]; [cell.cantidad setText:[Calculate calcMonto:cotizacion.comisionPorcentaje total:self.totalIdeal]]; [cell.porcentaje setText:[NSString stringWithFormat:@"%1.2f%@", [cotizacion.comisionPorcentaje doubleValue], @"%"]]; } else { [cell.nombre setText:@"Comision de Venta"]; [cell.cantidad setText:self.montoRealComision]; [cell.porcentaje setText:[NSString stringWithFormat:@"%1.2f%@", [cotizacion.comisionPorcentaje doubleValue], @"%"]]; } } </code></pre> <p><code>UITableViewCell</code> class:</p> <pre><code> - (id)initWithFrame:(CGRect)frame cell:(TableViewCells *)cell { if (self = [super initWithFrame:frame]) { _cell = cell; //self.opaque = YES; //self.backgroundColor = _cell.backgroundColor; } return self; } - (void)drawRect:(CGRect)rect { [_cell.arrowImage drawAtPoint:CGPointMake(0, 0)]; } @end @implementation TableViewCells @synthesize nombre; @synthesize porcentaje; @synthesize cantidad; @synthesize arrowImage; - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { // Initialization code UILabel *nombreLabel = [[UILabel alloc] initWithFrame:CGRectZero]; self.nombre = nombreLabel; [nombreLabel release]; [self.nombre setFont:[UIFont boldSystemFontOfSize:14]]; [self.contentView addSubview:self.nombre]; UILabel *porcentajeLabel = [[UILabel alloc] initWithFrame:CGRectZero]; self.porcentaje = porcentajeLabel; [porcentajeLabel release]; [self.porcentaje setFont:[UIFont italicSystemFontOfSize:10]]; [self.contentView addSubview:self.porcentaje]; UILabel *cantidadLabel = [[UILabel alloc] initWithFrame:CGRectZero]; self.cantidad = cantidadLabel; [self.cantidad setTextAlignment:UITextAlignmentRight]; [cantidadLabel release]; [self.cantidad setFont:[UIFont boldSystemFontOfSize:14]]; [self.contentView addSubview:self.cantidad]; cellContentView = [[TableViewCellContentView alloc] initWithFrame:CGRectZero cell:self]; cellContentView.backgroundColor = [UIColor clearColor]; [self.contentView addSubview:cellContentView]; } </code></pre> <p>UPDATE:</p> <p>I have also tried setting the image to a different one for everyone but one and I am still having the same issue.</p> <pre><code>- (void)configureCell:(TableViewCells *)cell atIndexPath:(NSIndexPath *)indexPath { cell.arrowImage = [UIImage imageNamed:@"arrowDown.png"]; switch (indexPath.row) { case 0: { if (indexPath.section == cotizacionIdeal) { cell.arrowImage = [UIImage imageNamed:@"arrowUp.png"]; [cell.nombre setText:@"Recursos"]; [cell.cantidad setText:[NSString stringWithFormat:@"%1.2f", [cotizacionPrevia.sueldoDeRecursos doubleValue]]]; [cell.porcentaje setText:[NSString stringWithFormat:@"%1.2f%@", [cotizacion.recursosPorcentaje doubleValue], @"%"]]; } else { </code></pre>
    singulars
    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.
 

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