Swift: 图片视图显示错误
Swift: Image view display wrong
我有 UIImageView
约束看起来像图片
TableviewCell
但是当从数组数据设置图像时,它显示错误(在imageView之外)
Image display wrong
我已经在 tableView 中设置了
cell.imgView.contentMode = .scaleAspectFill
cell.imgView.clipsToBounds = true
if self.arrDulieu[indexPath.row].attachment?.count ?? 0 > 0 {
cell.imageView!.image = UIImage(data: self.arrDulieu[indexPath.row].attachment![0])
}
应该是imgView
(自定义class的属性)不是imageView
(UITableViewCell
的属性class)
cell.imgView.image = UIImage(data: self.arrDulieu[indexPath.row].attachment![0])
尝试在主线程上设置图像
DispatchQueue.main.async {
if self.arrDulieu[indexPath.row].attachment?.count ?? 0 > 0 {
cell.imageView!.image = UIImage(data: self.arrDulieu[indexPath.row].attachment![0])
}
}
如果您使用故事板,请检查您的限制条件。
如果问题仍然存在,请 post 您的完整代码,以便正确理解问题。
谢谢!
@Sh_Khan 解决了这个问题。
我有 UIImageView
约束看起来像图片
TableviewCell
但是当从数组数据设置图像时,它显示错误(在imageView之外) Image display wrong
我已经在 tableView 中设置了
cell.imgView.contentMode = .scaleAspectFill
cell.imgView.clipsToBounds = true
if self.arrDulieu[indexPath.row].attachment?.count ?? 0 > 0 {
cell.imageView!.image = UIImage(data: self.arrDulieu[indexPath.row].attachment![0])
}
应该是imgView
(自定义class的属性)不是imageView
(UITableViewCell
的属性class)
cell.imgView.image = UIImage(data: self.arrDulieu[indexPath.row].attachment![0])
尝试在主线程上设置图像
DispatchQueue.main.async {
if self.arrDulieu[indexPath.row].attachment?.count ?? 0 > 0 {
cell.imageView!.image = UIImage(data: self.arrDulieu[indexPath.row].attachment![0])
}
}
如果您使用故事板,请检查您的限制条件。 如果问题仍然存在,请 post 您的完整代码,以便正确理解问题。 谢谢!
@Sh_Khan 解决了这个问题。