Photosから取得した写真をUICollectionViewで並べるphotopickerを作っています。
以下のコードで実機テストをしたところ、写真が表示されないセルが生じてしまいます。ページをスクロールすると、空白だったセルに写真が表示されるのですが、また他のセルが所々空白になってしまいます。
swift
1func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 2 3 //セルを取得する 4 let cell = collectionView.dequeueReusableCellWithReuseIdentifier("photoItem", forIndexPath: indexPath) as! photoPickerCollectionViewCell 5 6 cell.photo.image = nil 7 8 //用意した定数にphotosAssetsから写真データを取り出す 9 let asset = appDelegate.photosAssets[indexPath.row] 10 print(asset) 11 12 //ここで、写真データassetを表示している。 13 let manager:PHImageManager = PHImageManager() 14 manager.requestImageForAsset(asset,targetSize:CGSizeMake((self.view.frame.size.width-4)/3, (self.view.frame.size.width-4)/3) , contentMode: PHImageContentMode.AspectFill, options: nil, resultHandler: {(image,info) -> Void in 15 print(image) 16 17 cell.photo.image = image 18 19 }) 20 return cell 21 22 } 23 24
どのように修正すれば、正しく表示できるでしょうか。よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。