Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone table cell label misaligned

Tags:

Similar to this previous question, I am having a problem with text alignment in my table cells. All the text is shifted up by a few pixels. I am not using custom cells; I am using regular UITableViewCells with the UITableViewCellStyleValue1 style, targeting iPhone OS 3.1. I would prefer a much simpler solution than the previous question's answer, especially since I'm not using custom cells. I'd also like to know exactly what the problem is, since that part of the question was never addressed.

Here's what it looks like on the simulator:

Simulator http://www.shaggyfrog.com/junk/table-cell-label-misalignment-simulator.png

And on the device:

Device http://www.shaggyfrog.com/junk/table-cell-label-misalignment-device.png

Edit: some more code as per request. (I'm building my table cells outside of cellForRowAtIndexPath.)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [cells objectAtIndex:[indexPath row]];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self loadCells];
    [table reloadData];

    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)loadCells
{
    cells = [[NSArray alloc] initWithObjects:[self aCell], [self bCell], nil];
}

- (UITableViewCell*)aCell
{
    UITableViewCell* cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Foo"] autorelease];
    cell.textLabel.text = @"A";
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

- (UITableViewCell*)bCell
{
    UITableViewCell* cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Foo"] autorelease];
    cell.textLabel.text = @"B";
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
like image 905
Shaggy Frog Avatar asked Dec 10 '09 20:12

Shaggy Frog


1 Answers

I know your code says you are using cell style UITableViewCellStyleValue1, but the device screenshot really looks like UITableViewCellStyleSubtitle.

You should set a value for cell.detailTextLabel.text to make sure you are getting the expected cell style.

On that note, if you aren't going to use the detailTextLabel property, you should probably use UITableViewCellStyleDefault.

like image 180
benzado Avatar answered Oct 12 '22 01:10

benzado