gpt4 book ai didi

ios - 在 UITableViewCell 中设置图像时约束不起作用

转载 作者:行者123 更新时间:2023-11-28 11:35:39 24 4
gpt4 key购买 nike

当我在 cellForRowAt 函数中设置 UIImage 时,看起来我设置的 UIImageUIImageView 重叠>.

已编辑:clipsToBound 被标记并且 contentModeStoryboard 中设置为 .scaleAspectFit

我像往常一样在 Storyboard 中设置所有 Constraints:

enter image description here

但是当我运行该应用程序时,它看起来具有更高的优先级以压倒我设置的 Constraints,这就是我得到的结果:

enter image description here

不久前,我在其他项目中做了类似的事情,对我来说效果很好:

enter image description here

这是设置单元格的代码,但我很确定我只是不小心标记或取消标记了 Storyboard 中的某些内容:

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
}

如果需要任何其他信息,请告诉我,提前谢谢。

最佳答案

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 的默认 imageView。
您必须重命名您的自定义 UIImageView socket

关于ios - 在 UITableViewCell 中设置图像时约束不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55516132/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com