Tengo tres UILabel personalizado en UITableViewCell. El diseño de la célula de este tipo,¿Cambia la altura de UITableviewCell dinámicamente en iPhone?
Date(12.1.2012) Time(12.00pm)
Cost: $20.00
Details
he especificado la altura de la fila 100 en - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
. Pero, ahora los detalles algunas veces vuelven vacíos (nulos) desde el servidor. En ese momento necesito quitar la etiqueta Detalles de la celda y cambiar la altura de la celda particular (fila) a 70. ¿Cómo puedo hacer esto? Busqué mi mejor nivel en Google. Pero, todavía estoy confundido para hacer esto. ¿Podrías ayudarme? Gracias. Tengo una idea de este enlace: http://www.cimgf.com/2009/09/23/uitableviewcell-dynamic-height/
. Utilizaron solo una etiqueta para cambiar el tamaño de la altura de la fila. Por favor, ayúdame.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 90;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 100, 30)];
dateLabel.tag = 100;
dateLabel.backgroundColor = [UIColor clearColor];
dateLabel.font = [UIFont fontWithName:@"Helvetica" size:16];
dateLabel.font = [UIFont boldSystemFontOfSize:16];
dateLabel.highlightedTextColor = [UIColor whiteColor];
[cell.contentView addSubview: dateLabel];
UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(120, 0, 200, 25)];
timeLabel.tag = 101;
timeLabel.backgroundColor = [UIColor clearColor];
timeLabel.font = [UIFont fontWithName:@"Helvetica" size:14];
timeLabel.highlightedTextColor = [UIColor whiteColor];
[cell.contentView addSubview: timeLabel];
UILabel *costLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 300, 25)];
costLabel.tag = 102;
costLabel.backgroundColor = [UIColor clearColor];
costLabel.font = [UIFont fontWithName:@"Helvetica" size:14];
costLabel.font = [UIFont boldSystemFontOfSize:14];
costLabel.highlightedTextColor = [UIColor whiteColor];
[cell.contentView addSubview: costLabel];
UILabel *eventLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, 300, 25)];
eventLabel.tag = 103;
eventLabel.backgroundColor = [UIColor clearColor];
eventLabel.font = [UIFont fontWithName:@"Helvetica" size:14];
eventLabel.font = [UIFont boldSystemFontOfSize:14];
eventLabel.highlightedTextColor = [UIColor whiteColor];
[cell.contentView addSubview: eventLabel];
}
UILabel *dateLabel = (UILabel *) [cell.contentView viewWithTag:100];
dateLabel.text = [DateArray objectAtIndex:indexPath.row];
UILabel * timeLabel = (UILabel *) [cell.contentView viewWithTag:101];
timeLabel.text = [timeArray objectAtIndex:indexPath.row];
UILabel * costLabel = (UILabel *) [cell.contentView viewWithTag:102];
costLabel.text = [costArray objectAtIndex:indexPath.row];
UILabel *eventLabel = (UILabel *) [cell.contentView viewWithTag:103];
NSString *description = [eventArray objectAtIndex:indexPath.row];
if([description isEqualToString:@""])
{
eventLabel.text = @""; // Here i don't want to show this label and resize(reduce) the row height to 60;
}
else
{
eventLabel.text = description;
}
return cell;
}
¿Cómo puedo hacer esto? Gracias.
Sr.MadhavanRP gracias por su respuesta. He intentado tu respuesta en mi código. He comprobado la condición en cellForRowAtIndexPath: también. La primera vez funciona bien. Cuando me desplazo por la vista de tabla, el tamaño de la celda ha cambiado y la etiqueta de descripción ha cambiado la ubicación. Significa que la etiqueta de descripción tiene eliminar para todas las filas. Podrías ayudarme. gracias – Gopinath
@Gopinath por qué no intenta agregar la etiqueta de detalles como subvista de la celda solo cuando tiene alguna descripción. Es posible que necesite crear una clase personalizada para resolver el problema de desplazamiento. consulte la respuesta de esta pregunta http://stackoverflow.com/questions/8352530/changing-the-position-of-custom-uibutton-in-custom-uitableviewcell – MadhavanRP