Reputation: 27601
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 UITableViewCell
s 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;
}
Upvotes: 5
Views: 1980
Reputation: 84308
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
.
Upvotes: 5