3 つの UIImageView を持つカスタム テーブル ビュー セルがあります。Hanekeを使用して非同期でロードおよびキャッシュします。上にスクロールすると、以前に見た画像の一部がランダムに消えます。これは本当に奇妙です。なぜこうなった ?
SDWebImage も試しましたが、問題は解決しません。
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
}
カスタム テーブル ビュー セル:
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
}
}
...
}
私のテーブルビューコントローラ:
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
}