iPhone Device 3.1 SDK Interrompe l'allineamento verticale di UITableViewCellStyleValue1 textLabel
-
05-07-2019 - |
Domanda
Qualcuno può fornire una spiegazione per il seguente fenomeno?
A partire dall'SDK Device 3.1 di iPhone, ho scoperto che se un UITableViewCell
è di stile UITableViewCellStyleValue1
e il suo detailTextLabel.text
è non assegnato, quindi textLabel
non viene visualizzato al centro della cella come previsto.
Un avvertimento notevole è che questo accade solo per me quando sto testando sul Dispositivo - l'SDK per iPhone Simulator 3.1 mostra correttamente le celle. Inoltre, questo non è un problema quando si utilizza l'SDK di Device 3.0 per iPhone.
Di seguito è una semplice implementazione della sottoclasse UITableViewController
che dimostra il 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
Soluzione
anziché
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
prova a usare
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
Altri suggerimenti
Ho anche avuto lo stesso problema. La cella sembrava a posto nel simulatore ma quando ho eseguito l'app sul dispositivo il testo della cella non era centrato verticalmente. L'uso di UITableViewCellStyleDefault ha risolto i miei problemi di centraggio dell'allineamento verticale. Fortunatamente la mia cella non ha sottotitoli.