Ios 以编程方式在单元格中放置UImageView

Ios 以编程方式在单元格中放置UImageView,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个UITableViewCell*单元格,它有一个UIImageView*图像和一个UILabel*说明子视图。描述标签位于单元格的上部,我需要在标签和底部边缘之间找到UIImageView。这是我的密码: CGFloat bottomTextY = cell.labelDescription.frame.origin.y + cell.labelDescription.frame.size.height; CGFloat newImageY = bottomTextY + (cell.f

我有一个
UITableViewCell*单元格
,它有一个
UIImageView*图像
和一个
UILabel*说明
子视图。描述标签位于单元格的上部,我需要在标签和底部边缘之间找到
UIImageView
。这是我的密码:

CGFloat bottomTextY = cell.labelDescription.frame.origin.y + cell.labelDescription.frame.size.height;
CGFloat newImageY = bottomTextY + (cell.frame.size.height - bottomTextY) / 2;

cell.image.center = CGPointMake(cell.image.center.x, newImageY);

但每次位置不同时,标签和边缘之间并不严格。自动布局已关闭。请帮帮我!)

为了让你的生活更轻松,你应该在故事板中设计你的单元(原型单元)。该单元格将包含两个字段(图像和文本)。然后标记你的字段和

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
添加如下内容:

UIImageView * imageView = (UIImageView *)[cell viewWithTag:CELL_TAG_PHOTO];
imageView .image      = [self.photoSource objectForKey:key] ;

当然,每个元素的标记(编号)必须是唯一的,因为这是元素识别的方式(使用
#define CELL\u tag\u PHOTO(tag\u number)
定义它们)

设置UIImageView的框架,而不是中心属性

例如:

    cell.imageView .frame = CGRectMake(0, CGRectGetMaxY(cell.descriptionLabel.frame), cell.frame.size.width, cell.frame.size.height - CGRectGetMaxY(cell.descriptionLabel.frame));

你有一些截图来证明这一点吗?