【发布时间】:2015-07-23 20:17:03
【问题描述】:
我正在尝试将 PFFile 转换为 UIImage。它有效,但是,它似乎直到最后才运行。调用图像之后的行将图像附加到数组 (photosArray.append(image!)),但是当我这样做时,它不起作用,并且什么也不存储。我相信这是因为图像尚未完全检索,因为它正在背景中抓取图像。我如何不让它在后台保存,而是等到所有数据都加载完毕,然后附加到photosArray图像,所以数组不为空?
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.
【问题讨论】:
标签: ios image swift parse-platform