Ios 约束不';在TableViewCell中设置UIImage时不起作用

Ios 约束不';在TableViewCell中设置UIImage时不起作用,ios,swift,xcode,autolayout,Ios,Swift,Xcode,Autolayout,当我在cellForRowAt函数中设置UIImage时,我设置的UIImage看起来与UIImageView重叠 已编辑:clipsToBound已标记,contentMode在情节提要中设置为.scaleAspectFit 我正在像往常一样设置情节提要中的所有约束: 但是,当我运行应用程序时,它看起来比我设置的约束具有更高的优先级,这就是我得到的: 不久前,我在另一个项目中做了类似的事情,对我来说效果非常好: 下面是设置单元格的代码,尽管我很确定我只是在情节提要中意外地标记或取消标记了

当我在
cellForRowAt
函数中设置
UIImage
时,我设置的
UIImage
看起来与
UIImageView
重叠

已编辑:
clipsToBound
已标记,
contentMode
情节提要中设置为
.scaleAspectFit

我正在像往常一样设置
情节提要中的所有
约束

但是,当我运行应用程序时,它看起来比我设置的
约束具有更高的优先级,这就是我得到的:

不久前,我在另一个项目中做了类似的事情,对我来说效果非常好:

下面是设置单元格的代码,尽管我很确定我只是在
情节提要中意外地标记或取消标记了某些内容:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 100
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return songArray.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    guard let cell = tableView.dequeueReusableCell(withIdentifier: MainVCCell.CELL_ID, for: indexPath) as? MainVCCell else { return UITableViewCell() }
    cell.showLoader()
    cell.songNameLabel.text = songArray[indexPath.row].title

    if songImageArray[songArray[indexPath.row].title] != nil {
        cell.imageView?.image = songImageArray[songArray[indexPath.row].title]!!
        cell.hideLoader()
    }
    cell.setupImageDesign()
    return cell
}

如果需要任何附加信息,请提前通知我。

将图像视图
clipstobunds
设置为
true
将图像视图
clipstobunds
设置为
true
更改脚本中UIImageView的
contentMode

还可以设置脚本中UIImageView的
contentMode
更改


还可以设置
clipsToBounds=true
将ImageView的ContentMode更改为
。scalToFill
并将clipping属性更改为
cliptobunds

将ImageView的ContentMode更改为
。scalToFill
并将clipping属性更改为
cliptobunds

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    guard let cell = tableView.dequeueReusableCell(withIdentifier: MainVCCell.CELL_ID, for: indexPath) as? MainVCCell else { return UITableViewCell() }
    cell.showLoader()
    cell.songNameLabel.text = songArray[indexPath.row].title

    if songImageArray[songArray[indexPath.row].title] != nil {
        cell.imageView?.image = songImageArray[songArray[indexPath.row].title]!!
        cell.hideLoader()
    }
    cell.setupImageDesign()
    return cell
}
cell.imageView?.image
是UITableViewCell的默认图像视图。
您必须重命名自定义UIImageView插座

cell.imageView?.image
是UITableViewCell的默认图像视图。

您必须重命名自定义UIImageView插座

您在约束到页边距方面遇到问题

请删除所有约束,并确保在设置约束之前取消选中此选项

在故事板中看起来像这样


您在限制利润方面遇到问题

请删除所有约束,并确保在设置约束之前取消选中此选项

在故事板中看起来像这样


删除纵横比。没有帮助,加上我在上一个项目中使用了相同的约束条件,包括纵横比删除纵横比。没有帮助,加上我在上一个项目中使用了相同的约束条件,包括纵横比。我知道这样做很愚蠢,我打电话给UIImageView songImageView,但没有打电话给cell.songImageView,而是打了cell.imageView,非常感谢!呃,我知道这很愚蠢,我叫UIImageView songImageView,但叫cell.imageView而不是cell.songImageView,非常感谢!