[英]Loading and caching multiple UIImageView in a tableview cell not working
I have a custom table view cell with 3 UIImageView. 我有一个带有3 UIImageView的自定义表格视图单元格。 I load and cache them asynchroneously with Haneke . 我与Haneke异步加载和缓存它们。 When I scroll back up, some of the previoulsy seen images disappear randomly. 当我向上滚动时,一些以前看到的图像会随机消失。 This is really strange. 这真是奇怪。 Why is this happening ? 为什么会这样呢?
I have tried SDWebImage as well but the problem persisted. 我也尝试过SDWebImage,但问题仍然存在。
In setUserProfileImage, I use Haneke to load and cache my images : 在setUserProfileImage中,我使用Haneke加载和缓存图像:
import Haneke
func setUserProfileImage(image: UIImageView, userImageId:String) {
let url = NSURL(string:"http://localhost:3000/api/v1/users/" + userImageId + "/pictures?access_token="+Const.headers["x-access-token"]!)
image.hnk_setImageFromURL(url!)
rectangleImage(image)
}
func rectangleImage(image: UIImageView) {
image.roundCorners()
image.clipsToBounds = true
}
Custom table view cell : 自定义表格视图单元格:
class CustomTableViewCell: UITableViewCell {
@IBOutlet weak var profilePic: UIImageView!
@IBOutlet weak var profilePic2: UIImageView!
@IBOutlet weak var profilePic3: UIImageView!
var cellGroup : Group = Group()
func configureGroup (m: Group) {
cellGroup = m
}
func configureCell() {
setUsersImage()
}
func setUsersImage() {
setUserProfileImage(profilePic, userImageId: cellGroup.users[0].substringFromIndex(cellGroup.users[0].startIndex.advancedBy(1)))
if cellGroup.users.count > 1 {
setUserProfileImage(profilePic2, userImageId: cellGroup.users[1].substringFromIndex(cellGroup.users[1].startIndex.advancedBy(1)))
if (cellGroup.users.count > 2) {
setUserProfileImage(profilePic3, userImageId: cellGroup.users[2].substringFromIndex(cellGroup.users[2].startIndex.advancedBy(1)))
}
else {
profilePic3.hidden = true
}
}
else {
profilePic2.hidden = true
profilePic3.hidden = true
}
}
...
}
My table view controller : 我的表视图控制器:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CustomTableViewCell", forIndexPath: indexPath) as! CustomTableViewCell
reloadCellAtIndexPathRow(indexPath.row, cell: cell)
return cell
}
func reloadCellAtIndexPathRow(groupIndex : Int, cell: MomentTableViewCell) {
cell.configureGroup(groups[groupIndex])
cell.configureCell()
cell.selectionStyle = .None
cell.backgroundColor = nil
}
You never set the hidden UIImageView to reappear therefore they seem to be hidden only when reusued. 您永远不会将隐藏的UIImageView设置为重新出现,因此它们似乎仅在重新使用时才隐藏。
Change your code to 将您的代码更改为
func configureCell() {
profilePic3.hidden = false
profilePic2.hidden = false
setUsersImage()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.