Can anyone provide an explanation for the following phenomenon?
As of the iPhone Device 3.1 SDK, I've found that if a UITableViewCell
is of style UITableViewCellStyleValue1
and its detailTextLabel.text
is unassigned, then the textLabel
does not display in the center of the cell as would be expected.
One notable caveat is that this only happens for me when I'm testing on the Device – the iPhone Simulator 3.1 SDK displays the cells correctly. Also, this is not a problem when using the iPhone Device 3.0 SDK.
Below is a simple UITableViewController
subclass implementation that demonstrates the problem.
@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
instead of
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
try using
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With