Skip to content

Commit

Permalink
Fixed a bug that the updated cell has been reused.
Browse files Browse the repository at this point in the history
  • Loading branch information
CocoaBob committed Jul 2, 2018
1 parent 49a9324 commit 803e686
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion TLPhotoPicker/Classes/TLPhotosPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,10 @@ extension TLPhotosPickerViewController: UICollectionViewDelegate,UICollectionVie
let requestId = self.photoLibrary.imageAsset(asset: phAsset, size: self.thumbnailSize, options: options) { [weak cell] (image,complete) in
DispatchQueue.main.async {
if self.requestIds[indexPath] != nil {
if let currentCell = collectionView.cellForItem(at: indexPath) as? TLPhotoCollectionViewCell,
currentCell != cell {
cell = currentCell
}
cell?.imageView?.image = image
if complete {
self.requestIds.removeValue(forKey: indexPath)
Expand All @@ -846,6 +850,10 @@ extension TLPhotosPickerViewController: UICollectionViewDelegate,UICollectionVie
let requestId = self.photoLibrary.imageAsset(asset: phAsset, size: self.thumbnailSize, completionBlock: { (image,complete) in
DispatchQueue.main.async {
if self.requestIds[indexPath] != nil {
if let currentCell = collectionView.cellForItem(at: indexPath) as? TLPhotoCollectionViewCell,
currentCell != cell {
cell = currentCell
}
cell?.imageView?.image = image
if self.allowedVideo {
cell?.durationView?.isHidden = asset.type != .video
Expand Down Expand Up @@ -935,7 +943,7 @@ extension TLPhotosPickerViewController: UITableViewDelegate,UITableViewDataSourc
}

open func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TLCollectionTableViewCell", for: indexPath) as! TLCollectionTableViewCell
var cell = tableView.dequeueReusableCell(withIdentifier: "TLCollectionTableViewCell", for: indexPath) as! TLCollectionTableViewCell
let collection = self.collections[indexPath.row]
cell.thumbImageView.image = collection.thumbnail
cell.titleLabel.text = collection.title
Expand All @@ -945,6 +953,10 @@ extension TLPhotosPickerViewController: UITableViewDelegate,UITableViewDataSourc
let size = CGSize(width: 80*scale, height: 80*scale)
self.photoLibrary.imageAsset(asset: phAsset, size: size, completionBlock: { [weak cell] (image,complete) in
DispatchQueue.main.async {
if let currentCell = tableView.cellForRow(at: indexPath) as? TLCollectionTableViewCell,
currentCell != cell {
cell = currentCell
}
cell?.thumbImageView.image = image
}
})
Expand Down

0 comments on commit 803e686

Please sign in to comment.