iPhone表格单元格标签对齐单元格、表格、标签、iPhone

2023-09-11 07:44:20 作者:亲手扳倒你

类似于this previous问题,我在我的表格单元格具有文本对齐方式的一个问题。所有的文本上移几个像素。我没有使用自定义的细胞;我使用普通的的UITableViewCell s的的 UITableViewCellStyleValue1 的风格,针对iPhone OS 3.1。我想preFER一个比previous问题的回答更简单的解决方案,尤其是因为我没有使用自定义的细胞。我也想知道这个问题的正是的,因为这个问题一直没有解决的部分。

下面是它看起来像在模拟器上:

和设备上的:

编辑:一些更多的code为每个请求。 (我建设我的表格单元格的cellForRowAtIndexPath之外。)

   - (定义UITableViewCell *)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    返回[细胞objectAtIndex:[indexPath行]];
}

 - (无效)viewWillAppear中:(BOOL)动画
{
    [超级viewWillAppear中:动画]。

    [自称重传感器]
    [表reloadData];

    [self.navigationController setNavigationBarHidden:NO动画:YES];
}

 - (无效)称重传感器
{
    细胞= [[NSArray的页头] initWithObjects:自aCell],[自主B细胞],无]
}

 - (定义UITableViewCell *)aCell
{
    的UITableViewCell *电池= [[[UITableViewCell的页头] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@富]自动释放]。
    cell.textLabel.text = @A;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    返回细胞;
}

 - (定义UITableViewCell *)B细胞
{
    的UITableViewCell *电池= [[[UITableViewCell的页头] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@富]自动释放]。
    cell.textLabel.text = @B;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    返回细胞;
}
 
wps表格中我想点一下单元格就能自动标记可以吗

解决方案

我知道你的code说,你正在使用的单元格样式 UITableViewCellStyleValue1 ,但该设备的截图真的看起来像 UITableViewCellStyleSubtitle

您应该设置为 cell.detailTextLabel.text A值,以确保您得到预期的单元格样式。

在这一点,如果你不打算使用 detailTextLabel 属性,你应该使用 UITableViewCellStyleDefault

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:

And on the device:

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;
}

解决方案

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.