我正在提取用戶的Photo Asset
並嘗試在我的UICollectionView
中創建自定義UICollectionViewCell
,其中第一個索引是Camera Image
,其他單元格是相機圖像。但是,當我滾動,它像索引圖像重建,我發現在我的細胞一些圖片讓我在index[0]
UICollectionView CustomCell ReUse
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
//Deque an GridViewCell
let cell: GridViewCell = (collectionView.dequeueReusableCellWithReuseIdentifier(CellReuseIdentifier, forIndexPath: indexPath) as? GridViewCell)!
if indexPath.item != 0 {
let asset = assetsFetchResults[indexPath.item - 1] as! PHAsset
cell.representedAssetIdentifier = asset.localIdentifier
imageManager.requestImageForAsset(asset, targetSize: AssetGridThumbnailSize, contentMode: PHImageContentMode.AspectFill, options: nil) { (result: UIImage?, info: [NSObject : AnyObject]?) -> Void in
//print(result)
if cell.representedAssetIdentifier.isEqualToString(asset.localIdentifier) {
if let imageResult = result {
cell.imageView.image = imageResult
}
}
}
} else {
let cameraButton = UIButton(frame: CGRectMake(0,0,80,80))
cameraButton.setTitle("Camera", forState: .Normal)
cameraButton.frame = cell.imageView.bounds
cell.imageView.addSubview(cameraButton)
}
return cell
}
如下的添加視圖用於說明
如果單元格的類型不同,那麼您應該使用兩個不同的重用標識符。否則,它會重複使用相同的單元格 –
感謝您的建議@AlokRao –