UICollectionView
にカスタムセルを実装しようとしています。 セットアップが次です:私は、ダウンロードした画像のデータを取得する場合CollecitonViewが常にデータを正しく表示するとは限りません
- 4細胞
- =>そのイメージとセルのImageViewのを埋めます。
- else:プレースホルダを使用します。
PFFiles
の画像はimageFileDic:[String:PFFile]
に保存されます。今、時々(1/5)私のアプリケーションは、二度の画像を表示することを決定、または細胞NRの位置にある
let collectionCell:SettingsCollectionViewCell =
collectionView.dequeueReusableCellWithReuseIdentifier("collectionCell",
forIndexPath: indexPath) as! SettingsCollectionViewCell
if indexPath.row < imageFileDic.count {
if let imageId = imageFileIds[indexPath.row] as? String {
if let imageData = imageFileDic[imageId]{
collectionCell.collectionViewImage.file = imageData
collectionCell.collectionViewImage.loadInBackground()
}
}
} else{
collectionCell.collectionViewButton.setImage(UIImage(), forState: .Normal)
collectionCell.collectionViewImage.image = UIImage(named: "CameraBild.png")
}
:
これは私のがcellForItemAtIndexPath
に更新されます。 4.
私のクエリでは、私は常に新しいデータを追加する前に辞書と配列を削除しています。
アイデア?
編集: これは私が呼び出していますPFQuery
です:
let imageQuery = PFQuery(className: "Images")
imageQuery.whereKey("sender", equalTo: objectID!)
imageQuery.addAscendingOrder("createdAt")
imageQuery.cachePolicy = .NetworkElseCache
imageQuery.findObjectsInBackgroundWithBlock { (objects, error) in
if error != nil {
createAlert(error!)
}
else{
if let objects = objects{
self.imageFileDic.removeAll()
self.imageFileIds.removeAll()
for object in objects{
if let id = object.objectId{
print("id found")
if let imageFile = object.objectForKey("imageFile") as? PFFile{
self.imageFileIds.append(id)
self.imageFileDic[id] = imageFile
if object == objects.last{
print(self.imageFileIds.count)
print(self.imageFileDic.count)
self.mainCollectionView.reloadData()
}
}
}
}
}
}
}
}
に画像を更新するべきだと思います。私はあなたがcollectionCell.collectionViewImage.image = nillを最初からやっていないと確信しています。 –
cellForItemAtIndexPath全体を投稿するだけでなく、クエリコードを投稿し、非同期応答の処理方法を説明します。 –
再利用可能なセルは、セル項目の初期値を設定しないと仮定できます。 –