Soy un poco nuevo en el desarrollo de Objective-C y iPhone y me he encontrado con un problema al tratar de centrar el texto en una celda de tabla. He buscado en google, pero las soluciones son para un viejo error de SDK que se ha corregido y estos no funcionan para mí.Center Alinea el texto en el problema UITableViewCell
Algunos código:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = @"Please center me";
cell.textLabel.textAlignment = UITextAlignmentCenter;
return cell;
}
Lo anterior no centrar el texto.
También he probado el método willDisplayCell:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.textLabel.textAlignment = UITextAlignmentCenter;
}
y he probado algunas de las viejas soluciones publicadas:
UILabel* label = [[[cell contentView] subviews] objectAtIndex:0];
label.textAlignment = UITextAlignmentCenter;
return cell;
Ninguno de ellos tiene ningún efecto sobre la alineación del texto. Me he quedado sin idea de que cualquier ayuda sería muy apreciada.
Saludos con anticipación.
UITextAlignment está en desuso en iOS 6.0, ahora es NSTextAlignment – Souljacker