我正在尝试与AWS SDK集成,但图像不显示。
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("MyCollectionViewCell", forIndexPath: indexPath) as! MyCollectionViewCell
let downloadURL = NSURL(fileURLWithPath: NSTemporaryDirectory()).URLByAppendingPathComponent("myImage.jpg")
let downloadRequest = AWSS3TransferManagerDownloadRequest()
downloadRequest.bucket = "stg"
downloadRequest.key = "myImage.jpg"
downloadRequest.downloadingFileURL = downloadURL
let transferManager = AWSS3TransferManager.defaultS3TransferManager()
transferManager.download(downloadRequest).continueWithBlock { (task) -> AnyObject! in
if task.error != nil {
print("Failed to download S3 with error \(task.error)")
}
if task.result != nil {
//let output = task.result as! AWSS3TransferManagerDownloadOutput
cell.imageView.contentMode = UIViewContentMode.ScaleAspectFit
cell.imageView?.hnk_setImageFromURL(downloadURL)
}
return nil
}
return cell
}发布于 2015-11-19 03:27:51
问题是您正在后台线程中更新UI。您应该用.continueWithExecutor(AWSExecutor.mainThreadExecutor(), withBlock: { (task) -> AnyObject! in替换.continueWithBlock { (task) -> AnyObject! in,以便在主线程中运行该块。
此外,如果您正在编写新的应用程序,我建议使用AWSS3TransferUtility而不是AWSS3TransferManager,因为我们将把开发重点放在传输实用程序上,并将逐步淘汰对传输管理器的支持。
https://stackoverflow.com/questions/33774910
复制相似问题