【问题标题】:running a func after getDataInBackgroundWithBlock在 getDataInBackgroundWithBlock 之后运行一个函数
【发布时间】:2014-10-20 11:46:23
【问题描述】:

全部,我快速运行此函数以获取(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)
    }
}

但这总是 - 徽标是空的,因为它在 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..

【问题讨论】:

    标签: swift parse-platform


    【解决方案1】:

    我已经解决了这个问题

      }, progressBlock: {(percentDone: CInt) -> Void in
    
        })
    

    使用 CInt 而不是 Int

    【讨论】:

    • 如果您不介意可以发布完整的功能吗?我正在尝试解决同样的问题。
    猜你喜欢
    • 2018-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-21
    • 1970-01-01
    • 1970-01-01
    • 2022-09-23
    • 2018-05-04
    相关资源
    最近更新 更多