Dispositivo iPhone 3,1 SDK quebras alinhamento vertical de UITableViewCellStyleValue1 textLabel

StackOverflow https://stackoverflow.com/questions/1408105

  •  05-07-2019
  •  | 
  •  

Pergunta

Alguém pode fornecer uma explicação para o seguinte fenômeno?

A partir do dispositivo iPhone 3.1 SDK, eu encontrei que se um UITableViewCell é de UITableViewCellStyleValue1 estilo e sua detailTextLabel.text é não atribuído, então o textLabel não exibe no centro da célula como seria de esperar.

Uma ressalva notável é que isso só acontece para mim quando eu estou testando no dispositivo - o iPhone Simulator 3.1 SDK exibe as células corretamente. Além disso, este não é um problema quando utilizar o dispositivo iPhone 3.0 SDK.

A seguir é a implementação de um simples UITableViewController subclasse que demonstra o problema.

@implementation BuggyTableViewController

#pragma mark Table view methods


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
    }

    switch (indexPath.row) {
  case 0:
   cell.textLabel.text = @"detailTextLabel.text unassigned";
   break;
  case 1:
   cell.textLabel.text = @"detailTextLabel.text = @\"\"";
   cell.detailTextLabel.text = @"";
   break;
  case 2:
   cell.textLabel.text = @"detailTextLabel.text = @\"A\"";
   cell.detailTextLabel.text = @"A";
   break;
  default:
   break;
 }

    return cell;
}

@end
Foi útil?

Solução

em vez de

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];

tente usar

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

Outras dicas

Eu também tive o mesmo problema. A célula parecia bem no simulador, mas quando eu corria o aplicativo no dispositivo do texto da célula não estava centrado na vertical. Usando UITableViewCellStyleDefault resolvido meus problemas de alinhamento de centragem vertical. Felizmente o meu celular não tem um subtítulo.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top