我試圖從用戶的相冊中加載所有圖像到我的應用程序的收藏視圖中,但是加載了幾個他們,應用程序將關閉並返回到主菜單。與XCode的連接也被斷開。 這不會發生在模擬器,但只有我正在測試的iPhone 4s。 出現崩潰之前,在出現的順序的錯誤消息,將照片中的圖像加載到收藏視圖會導致出現錯誤消息「連接資產被中斷或資產死亡」
- 接收的存儲器警告
- 連接到assetsd被中斷或assetsd死亡。
我已經拿起了我認爲會導致這個問題的代碼的幾個部分。
var imgFetchResult: PHFetchResult!
override func viewDidLoad() {
super.viewDidLoad()
let fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]
let fetchResult = PHAsset.fetchAssetsWithMediaType(PHAssetMediaType.Image, options: fetchOptions)
if fetchResult.count > 0
{
println("images found ? \(fetchResult.count)")
self.imgFetchResult = fetchResult
}
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
println("cellForItemAtIndexPath")
let cell: PhotoThumbnailCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as PhotoThumbnailCollectionViewCell
println("indexpath is \(indexPath.item)")
if(indexPath.item == 0)
{
cell.backgroundColor = UIColor.redColor() //temp placeholder for camera image
}
else
{
let asset: PHAsset = self.imgFetchResult[indexPath.item] as PHAsset
PHImageManager.defaultManager().requestImageForAsset(asset, targetSize: PHImageManagerMaximumSize, contentMode: .AspectFill, options: nil, resultHandler: {(result, info) in cell.setThumbnailImage(result)
})
}
return cell
}
我相信我需要釋放內存,但不知道該怎麼做。它似乎是正在加載到集合視圖的單元格中的圖像。
我也發現收集視圖不超過4張圖片。在第四張圖像後,發生崩潰。此外,圖像未按順序加載。
這個驚人的,請你告訴我,我有多大的尺寸?正如你告訴我給出了105和105,但圖像不清晰,我必須通過什麼值來顯示圖像質量 – 2017-02-14 11:01:11
你可以這樣做: let targetSize = CGSize(width:asset.pixelWidth/2,height:asset。 pixelHeight/2) – jamesthakid 2017-10-10 17:10:09