Vorrichtung iPhone 3.1 SDK Bricht vertikale Ausrichtung von UITableViewCellStyleValue1 textlabel
-
05-07-2019 - |
Frage
Kann mir jemand eine Erklärung für das folgende Phänomen liefern?
Wie das iPhone-Geräts 3.1 SDK, habe ich festgestellt, dass, wenn ein UITableViewCell
Stil UITableViewCellStyleValue1
ist und seine detailTextLabel.text
ist nicht zugewiesen, dann ist die textLabel
nicht in der Mitte der Zelle anzeigt, wie zu erwarten ist.
Ein bemerkenswerter Nachteil ist, dass dies nur für mich passiert, wenn ich die Prüfung auf dem Gerät - das iPhone Simulator 3.1 SDK zeigt die korrekt Zellen. Auch das ist kein Problem, wenn das iPhone Gerät 3.0 SDK.
Im Folgenden finden Sie eine einfache UITableViewController
Unterklasse-Implementierung, die das Problem veranschaulicht.
@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
Lösung
statt
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
versuchen Sie es mit
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
Andere Tipps
Ich hatte auch das gleiche Problem. Die Zelle sah im Simulator in Ordnung, aber wenn ich die App auf dem Gerät der Zelle Text lief wurde nicht vertikal zentriert. Mit UITableViewCellStyleDefault gelöst meinen vertikalen Ausrichtung Zentrierung Probleme. Zum Glück meiner Zelle keinen Untertitel.