【发布时间】:2009-12-10 20:53:35
【问题描述】:
类似于this previous question,我的表格单元格中的文本对齐有问题。所有文本都向上移动了几个像素。我没有使用自定义单元格;我正在使用带有UITableViewCellStyleValue1 样式的常规UITableViewCells,针对iPhone OS 3.1。我更喜欢比上一个问题的答案更简单的解决方案,特别是因为我没有使用自定义单元格。我还想确切地知道问题是什么,因为这部分问题从未得到解决。
这是模拟器上的样子:
Simulator http://www.shaggyfrog.com/junk/table-cell-label-misalignment-simulator.png
在设备上:
Device 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;
}
【问题讨论】:
-
我们能看到
cellForRowAtIndexPath代码吗?我以前使用过UITableViewCellStyleValue1没有看到这个问题。 -
当然,我可以添加它,但我不确定它会有多大用处。
-
我以前从未见过这样创建的单元格……不过它们看起来还不错。也许你没有显示的代码中的其他东西是罪魁祸首?
-
可能。我以前构建过这样的单元格(包括在这个应用程序中)并且以前从未见过这个问题。就像上一个问题一样,好像子视图以某种方式错位,但偏差很小。
标签: iphone uitableview label alignment