iPhone Device 3.1 SDK rompt l'alignement vertical de UITLeViewCellStyleValue1 textLabel
-
05-07-2019 - |
Question
Quelqu'un peut-il expliquer le phénomène suivant?
Depuis le SDK Device Device 3.1 pour iPhone, j'ai constaté que si un UITableViewCell
était de style UITableViewCellStyleValue1
et que son detailTextLabel.text
était non attribué, le textLabel
ne s'affiche pas au centre de la cellule, comme on pouvait s'y attendre.
Un inconvénient notable est que cela ne se produit que pour moi lorsque je teste sur le périphérique & # 8211; Le SDK iPhone Simulator 3.1 affiche les cellules correctement. En outre, cela ne pose pas de problème lors de l’utilisation du kit de développement logiciel (SDK) pour iPhone Device 3.0.
Ci-dessous, une implémentation simple de UITableViewController
qui illustre le problème.
@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
La solution
au lieu de
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
essayez d'utiliser
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
Autres conseils
J'ai aussi eu le même problème. La cellule avait l'air bien dans le simulateur, mais lorsque j'ai lancé l'application sur l'appareil, le texte de la cellule n'était pas centré verticalement. Utiliser UITableViewCellStyleDefault a résolu mes problèmes de centrage d'alignement vertical. Heureusement, ma cellule n’a pas de sous-titre.