类似 this previous question ,我的表格单元格中的文本对齐有问题。所有文本都上移了几个像素。我没有使用自定义单元格;我用的是普通的 UITableViewCell 这是我的错 UITableViewCellStyleValue1 风格,针对iPhone OS 3.1。我更喜欢比上一个问题的答案简单得多的解决方案,特别是因为我没有使用自定义单元格。我也想知道到底是什么问题 ,因为问题的这一部分从未得到解决。
UITableViewCell
UITableViewCellStyleValue1
以下是它在模拟器上的外观:
Simulator http://www.shaggyfrog.com/junk/table-cell-label-misalignment-simulator.png
在设备上:
Device http://www.shaggyfrog.com/junk/table-cell-label-misalignment-device.png
编辑:根据请求添加一些代码(我正在CellForRowatineXpath之外构建表格单元格。)
- (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; }
我知道你的代码说你使用的是单元格样式 UITableViewCellStyleValue1 UITableViewCellStyleSubtitle .
UITableViewCellStyleSubtitle
您应该为设置一个值 cell.detailTextLabel.text
cell.detailTextLabel.text
detailTextLabel 属性,您可能应该使用 UITableViewCellStyleDefault
detailTextLabel
UITableViewCellStyleDefault