【问题标题】:Error when retrieving PFFile via getDataInBackgroundWithBlock通过 getDataInBackgroundWithBlock 检索 PFFile 时出错
【发布时间】:2015-08-22 11:41:55
【问题描述】:

我创建了一个var userImages = [PFFile](),并通过用户查询和self.userImages.append(user["imageFile"] as! PFFile) 附加了来自 Parse 的相应用户图像。这工作正常。但是,当我尝试通过

设置用户的图像时

userImages.getDataInBackGroundWithBlock{ (data, error) -> Void in ...

我收到以下错误:**'[(PFFile)]' does not have a member named 'getDataInBackGroundWithBlock'**

为什么这不起作用?有什么办法可以解决这个问题?

谢谢你的帮助!!

【问题讨论】:

    标签: swift parsing pffile


    【解决方案1】:

    您正在尝试在数组中调用getDataInBackGroundWithBlock 尝试使用“

    userImages.last?.getDataInBackGroundWithBlock{...}
    

    或者您可以将其保存在变量中并使用新的 PFFIle 来检索图像

    let userImage = user["imageFile"] as! PFFile
    userImage.getDataInBackGroundWithBlock{...}
    

    或直接使用:

    (user["imageFile"] as! PFFile).getDataInBackGroundWithBlock{...}
    

    角色进程是:

    self.userImages.append(user["imageFile"] as! PFFile) //This is just a reference to download the image
    
    userImages.last?.getDataInBackgroundWithBlock {
      (imageData: NSData?, error: NSError?) -> Void in
      if error == nil {
        if let imageData = imageData {
            let image = UIImage(data:imageData) // this is the final image
        }
      }
    }
    

    【讨论】:

    • 感谢您的快速答复! userImages.last?没有向我显示图像,但这或多或少正是我想要做的。有没有其他方法可以从我的数组中访问第一个 Image 或 PFFile,例如 userImages[indexPath.row] (使用 indexPath 会导致错误:is unresolved identifier)?不幸的是,您的其他建议没有从我的数组中检索任何图像。
    • 对不起,我可能表达得很糟糕,我不确定你想做什么,所以我向你展示了几个选项,只是第一个使用数组,其他两个只是更直接的方法。 Parse 最初不会向您发送图像而是图像的链接,最终图像将从 getDataInBackGroundWithBlock 块中检索
    • 非常感谢您的帮助!我使用您的代码检索文件,但 UIImageView 中没有显示图片。这是我用于查询和检索图像的两个代码。我正在寻找任何错误,但代码似乎很好......也许我的方法可能是错误的。稍后我会提供代码截图的链接。
    • 我刚刚编辑了我的帖子,并为您提供了我的代码的屏幕截图。希望这会有所帮助,我们可以解决这个问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-02
    • 1970-01-01
    • 1970-01-01
    • 2015-08-27
    • 2021-11-05
    • 1970-01-01
    相关资源
    最近更新 更多