私は画像付きのコレクションビューを持っています。ネットワークコードにAlamofireとAlamofireImageを使用しています。 cellForItemAtIndexPathの先頭で、画像をnilに設定し、飛行中のリクエストが存在する場合は、リクエスト?.cancel()を使用してキャンセルします。 これを行うと、一部のセルには画像がまったく入力されません。 私が間違っていることを私に見せてもらえますか? 以下の私のcellForItemAtIndexPathコードを参照してください:request.cancel()再利用セル用Alamofire swift
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! StoreCell
let entry = self.dataCell.addCell[indexPath.section][indexPath.item]
stringURL = "https://website.com/stories_db/images/\(entry.filename)"
cell.title.text = entry.title
cell.subTitle.text = entry.author
cell.cost.text = entry.cost
// Reset the cell
cell.storyImage.image = nil
// request?.cancel()
if let image = dataCell.cachedImage(stringURL) {
cell.storyImage.image = image
} else {
request = dataCell.getNetworkImage(stringURL) { image in
cell.storyImage.image = image
}
}
// Fix the collection view cell in size
cell.contentView.frame = cell.bounds
cell.contentView.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]
return cell
}