I have a custom table view cell with 3 UIImageView. I load and cache them asynchroneously with 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.
In setUserProfileImage, I use Haneke to load and cache my images :
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.
Change your code to
func configureCell() {
profilePic3.hidden = false
profilePic2.hidden = false
setUsersImage()
}