iPhone Device 3.1 SDK rompe la alineación vertical de UITableViewCellStyleValue1 textLabel

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

  •  05-07-2019
  •  | 
  •  

Pregunta

¿Alguien puede proporcionar una explicación para el siguiente fenómeno?

A partir del iPhone Device 3.1 SDK, he encontrado que si un UITableViewCell es de estilo UITableViewCellStyleValue1 y su detailTextLabel.text es sin asignar, entonces textLabel no se muestra en el centro de la celda como se esperaría.

Una advertencia notable es que esto solo me sucede cuando estoy probando en el Dispositivo : el Simulador del iPhone 3.1 SDK muestra las celdas correctamente. Además, esto no es un problema al usar el iPhone Device 3.0 SDK.

A continuación se muestra una implementación de subclase UITableViewController sencilla que demuestra el 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
¿Fue útil?

Solución

en lugar de

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

intenta usar

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

Otros consejos

También tuve el mismo problema. La celda se veía bien en el simulador, pero cuando ejecuté la aplicación en el dispositivo, el texto de la celda no estaba centrado verticalmente. El uso de UITableViewCellStyleDefault resolvió mis problemas de centrado de alineación vertical. Afortunadamente, mi celular no tiene un subtítulo.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top