如同上一个问题 https://stackoverflow.com/questions/1770872/text-misalignment-on-tableview-cells-on-iphone-device,我的表格单元格中的文本对齐有问题。所有文本都向上移动几个像素。我没有使用自定义单元格;我正在使用常规UITableViewCell
与UITableViewCellStyleValue1
风格,针对 iPhone OS 3.1。我更喜欢比上一个问题的答案更简单的解决方案,特别是因为我没有使用自定义单元格。我也想知道到底是什么问题is,因为问题的这一部分从未得到解决。
这是模拟器上的样子:
模拟器 http://www.shaggyfrog.com/junk/table-cell-label-misalignment-simulator.png http://www.shaggyfrog.com/junk/table-cell-label-misalignment-simulator.png
在设备上:
设备 http://www.shaggyfrog.com/junk/table-cell-label-misalignment-device.png http://www.shaggyfrog.com/junk/table-cell-label-misalignment-device.png
编辑:根据要求添加一些代码。 (我正在 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;
}
我知道你的代码说你正在使用单元格样式UITableViewCellStyleValue1
,但设备截图确实看起来像UITableViewCellStyleSubtitle
.
您应该设置一个值cell.detailTextLabel.text
以确保您获得预期的单元格样式。
请注意,如果您不打算使用detailTextLabel
属性,你可能应该使用UITableViewCellStyleDefault
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)