Pregunta

Parece que no puedo hacer que el texto realmente abarque varias líneas. Las alturas se ven correctas. ¿Qué me estoy perdiendo?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell =  [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"StatusCell"] autorelease];

    CGRect frame = cell.contentView.bounds;
    UILabel *myLabel = [[UILabel alloc] initWithFrame:frame];
    myLabel.text = [[person.updates objectAtIndex:indexPath.row] valueForKey:@"text"];
    [cell.contentView addSubview:myLabel];

    [myLabel release];

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    NSString *text = [[person.updates objectAtIndex:indexPath.row] valueForKey:@"text"];
    UIFont *font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
    CGSize withinSize = CGSizeMake(tableView.frame.size.width, 1000);
    CGSize size = [text sizeWithFont:font constrainedToSize:withinSize lineBreakMode:UILineBreakModeWordWrap];

    return size.height + 20;    
}

Además, ¿qué me falta para que las etiquetas aparezcan más largas que la celda de la tabla? texto alternativo ??

¿Fue útil?

Solución

Tweetero proporciona un ejemplo de esto en MessageListController.m . El código allí muestra la siguiente pantalla:

(La foto está tomada de Mashable ).

El esquema básico de implementación:

  1. Al construir un UITableViewCell , cree y agregue un UILabel como una subvista de la manera que se muestra en tableviewCellWithReuseIdentifier: . Busque la creación de la etiqueta TEXT_TAG .

  2. al enriquecer el UITableViewCell con vistas, asegúrese de formatear la etiqueta correctamente, como se hace en configureCell: forIndexPath , busque de manera similar la etiqueta etiqueta TEXT_TAG .

  3. Devuelve la altura adecuada para cada celda, como se hace en tableView:heightForRowAtIndexPath.

Otros consejos

myLabel.numberOfLines = 2;

Verifique documentos para obtener información completa sobre cómo usar esta propiedad.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return theSizeYouWantYourCellToBe;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top