Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone Device 3.1 SDK Breaks vertical alignment of UITableViewCellStyleValue1 textLabel

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
like image 261
Andrew Hershberger Avatar asked Oct 15 '22 13:10

Andrew Hershberger


1 Answers

instead of

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];

try using

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
like image 58
Mihir Mehta Avatar answered Oct 20 '22 03:10

Mihir Mehta