我已将UIImageView放置在我的自定义单元格中(Swift 3):
let cell = self.tableView.dequeueReusableCell(withIdentifier: "Feedcell", for: indexPath) as! FruitTableViewCell
let hero: List_Feed
hero = heroes[indexPath.row]
if(hero.photo==""){
cell.cnHeight.constant = 0
cell.cnTopMargin.constant = 0
cell.cnBottomMargin.constant = 52
cell.imgPhoto.image = UIImage()
cell.imgPhoto.frame = CGRect(x: 0, y: 0, width: 0, height: 0)
}else{
cell.cnTopMargin.constant = 14
cell.cnBottomMargin.constant = 50
cell.imgPhoto.frame = CGRect(x: 0, y: 0, width: 0, height: 0)
//displaying image
Alamofire.request(hero.photo!).responseImage { response in
debugPrint(response)
if let image = response.result.value {
//let newWidth = containerView.frame.height * ratio
let bounds = UIScreen.main.bounds
let width = bounds.size.width
let imagewidth = image.size.width
let imageheight = image.size.height
let ot1 = width / imagewidth
let ot2 = round(ot1 * imageheight)
//let ot3 = round(ot2 / 2)
//let ot4 = ot3 - 12
//let ot5 = ot4 + 50
cell.cnHeight.constant = ot2
cell.imgPhoto.image = image
}
}
}
当我向下滚动然后向上滚动时,它是如何显示的:
答案 0 :(得分:0)
尝试添加
DispatchQueue.main.async {
// all your ui code
}
你可能还在后台线程上。