Iphone 在UItableViewCell中居中UIImageView不会';不工作,如何修复?

Iphone 在UItableViewCell中居中UIImageView不会';不工作,如何修复?,iphone,ios,uitableview,uiimageview,Iphone,Ios,Uitableview,Uiimageview,我可以对单元格进行子分类并解决问题,但我想知道为什么这不起作用 我在单元格中设置了一个图像,然后在此方法中,我将图像向右移动: - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { [cell.imageView setFrame:CGRectMake(cell.contentVi

我可以对单元格进行子分类并解决问题,但我想知道为什么这不起作用

我在单元格中设置了一个图像,然后在此方法中,我将图像向右移动:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
        [cell.imageView setFrame:CGRectMake(cell.contentView.bounds.size.width/2 - cell.imageView.frame.size.width/2 + 100,
                                            cell.contentView.bounds.size.height/2 - cell.imageView.frame.size.height/2,
                                            cell.imageView.frame.size.width,
                                            cell.imageView.frame.size.height)];
        NSLog(@"center: %@", NSStringFromCGPoint(cell.imageView.center));
        NSLog(@"frame: %@", NSStringFromCGRect(cell.imageView.frame));
}
请注意我添加的+100,以确保它位于右侧

当我检查控制台时,它表明:

中心:{250,57.5}

帧:{150,7.5},{200,100}

然而,结果是:


图像仍与左侧对齐。这可以更改吗?如果可以,如何更改?

您不能移动图像视图。解决方案是或在drawRect中创建子类并进行自己的绘图,或向cell.contentView添加子视图

编辑:

如果设置了图像,则它将显示在单元格的左侧,然后 任何标签。UITableViewCell在您创建图像时创建图像视图对象 创建单元格


如果转到UITableViewCell的头文件,您将在那里找到

> // Content.  These properties provide direct access to the internal
> label and image views used by the table view cell.  These should be
> used instead of the content properties below.
> @property(nonatomic,readonly,retain) UIImageView  *imageView
> __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);   // default is nil.  image view will be created if necessary.

因此,正如您所看到的,它对图像视图显示readOnly属性。。。我想这就解释了您无法移动imageView的原因。

您能指出文档中确认的位置吗?我找遍了,什么也没找到。