首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PFFile to UIImage in Parse (ios)

PFFile to UIImage in Parse (ios)
EN

Stack Overflow用户
提问于 2015-07-23 20:17:03
回答 1查看 542关注 0票数 0

我正在尝试将PFFile转换为UIImage。然而,它似乎要到最后才能运行。在图像被调用后的行将图像追加到数组(photosArray.append( image !)),但是当我这样做时,它就不工作了,并且什么也不存储。我相信这是因为图像还没有被完全检索,因为它是在获取背景中的图像。我如何不让它保存在后台,但等到所有数据加载,然后附加到photosArray图像,所以数组不是空的?

代码语言:javascript
复制
var photosArray = [UIImage]()
let photosValue = log["Images"] as! PFFile
    photosValue.getDataInBackgroundWithBlock({
        (imageData: NSData?, error:NSError?) -> Void in
            if (error == nil) {
                let image = UIImage(data:imageData!)
                //line below appends nothing!  photosArray is an empty array, []
                photosArray.append(image!)
                //following line of code doesnt run until the end.  Is the last line to be printed in console.
                println("Our Image: \(image)")
            }
    })
    //prints "[]", no value
    println(photosArray)
    println("Our Image Array^^")

}

//after all the code is ran, the println("Our Image: \(image)") will run, 
//and say "Our Image: Optional(<UIImage: 0x16f0ead0>, {394, 256})".
//This is the last line of the console logged, so it IS saving, but not until the end.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-23 20:30:14

这不是一个正确的假设,getDataInBackgroundWithBlock的全部目的是处理响应数据。你也不能分配

代码语言:javascript
复制
let image = UIImage(data: imageData!)

如果是零。

我不确定您所指的println语句是什么,但是在后台仍在收集数据时打印出数组可能不会给出结果,只是

代码语言:javascript
复制
[]

但你应该看看

代码语言:javascript
复制
println("Our image: \(image)")

如果您计划在UIImageView中显示这些图像,我建议查看ParseUI类PFImageView,它有一个属性,您可以为它分配一个PFFile,然后是一个加载它的方法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31597255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档