作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所有,我在 swift 中运行这个函数来获取(UImages)数组中的图像
func getImageData(objects: [PFObject]) {
for object in objects {
let thumbNail = object["StaffPic"] as PFFile
thumbNail.getDataInBackgroundWithBlock({
(imageData: NSData!, error: NSError!) -> Void in
if (error == nil) {
let image = UIImage(data:imageData)
println(image)
self.logoImages.append(image)
执行此函数后,我可以使用什么东西在主线程上运行函数吗? 我创建了一个测试函数:
func displayImages()
{
if self.logoImages.isEmpty
{
println("Logos are empty")
}
else
{
println(self.logoImages.count)
}
}
但这始终是 - Logos 是空的,因为它在 getDataInBackgroundBlock 完成之前运行它。任何帮助都会很棒。
如果我添加这个:
func getImageData(objects: [PFObject]) {
for object in objects {
let thumbNail = object["StaffPic"] as PFFile
thumbNail.getDataInBackgroundWithBlock({
(imageData: NSData!, error: NSError!) -> Void in
if (error == nil) {
let image = UIImage(data:imageData)
println(image)
self.logoImages.append(image)
}
}, progressBlock: {
(percentDone: Int) -> Void in
})
所以我在函数末尾添加了progressBlock。它无法识别progressBlock..
最佳答案
我已经修复了这个问题
}, progressBlock: {(percentDone: CInt) -> Void in
})
使用 CInt 而不是 Int
关于swift - 在 getDataInBackgroundWith Block 之后运行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26464930/
所有,我在 swift 中运行这个函数来获取(UImages)数组中的图像 func getImageData(objects: [PFObject]) { for object in
我是一名优秀的程序员,十分优秀!