Pergunta

Eu não consigo obter o texto para realmente abranger várias linhas. As alturas parecem corretas. O que eu estou ausente?

- (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;    
}

Além disso, o que estou ausente que faz com que os rótulos aparecem mais do que a célula da tabela? text alt

Foi útil?

Solução

Tweetero fornece um exemplo disso na MessageListController.m . O código não torna a tela a seguir:

(Pic é retirado Mashable ).

O esquema básico de implementação:

  1. Ao construir um UITableViewCell, criar e adicionar um UILabel como um subview da maneira mostrada na tableviewCellWithReuseIdentifier:. Olhar para a criação de etiqueta TEXT_TAG.

  2. quando enriquecendo o UITableViewCell com vistas, garantir que você formatar rótulo corretamente, como é feito em configureCell:forIndexPath, semelhante procurar o TEXT_TAG tag rótulo.

  3. Voltar a altura apropriada para cada célula, como é feito em tableView:heightForRowAtIndexPath.

Outras dicas

myLabel.numberOfLines = 2;

Verifique a docs para informação completa sobre como usar essa propriedade.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return theSizeYouWantYourCellToBe;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top