我试图从用户的相册中加载所有图像到我的应用程序的收藏视图中,但是加载了几个他们,应用程序将关闭并返回到主菜单。与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