Swift 2.0:需要在Parse上的PFQueryTableViewController上显示图像(PFFile)吗?

时间:2015-11-30 17:02:02

标签: ios swift uitableview parse-platform

我试图将图片(文件)从Parse检索到PFQueryTableViewController。我在下面写了我的代码。我认为这是正确的,但也许有一些我想念的小事。我想看到图像显示,但我看到的只是空白的图像应该是什么。图像也是Parse。我之前尝试过这个实例并且它已经工作但是出于某种原因我不认为它适用于这种情况。那么如何从解析中检索图像以显示在查询上?

    let query = PFQuery(className: "Test")

    if let query = profilePage {

        pencil = NSMutableArray()

        query.addAscendingOrder("createdAt")

        query.findObjectsInBackgroundWithBlock {(objects: [AnyObject]?, error: NSError?) -> Void in

            if error == nil {               
                for object in objects! {

                    let pencil : PFObject = object as! PFObject
                    self.pencil.addObject(pencil)                 
                }

                let array : NSArray = self.pencil.reverseObjectEnumerator().allObjects

                self.pencil = NSMutableArray(array: array)

                self.tableView.reloadData()

            } else {


            }
        }

    }
}
        override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?, object: PFObject!) -> PFTableViewCell? {
       let cell = tableView!.dequeueReusableCellWithIdentifier("TakerCell", forIndexPath: indexPath!) as! TestTaker


        if let uTest : PFObject = self.pencil.objectAtIndex(indexPath!.row) as! PFObject {
        cell.testWriter.text = posts["taker"] as? String
        cell.testInfo.text = posts["information"] as? String
        if let photo = object["picture"] as? PFFile {
        let PFimageV = cell.userImg as PFImageView
        PFimageV.image = UIImage(named: "userImage")
        PFimageV.file = photo
        PFimageV.layer.cornerRadius = imageView.frame.width/2
        PFimageV.clipsToBounds = true
        PFimageV.loadInBackground()

            }

            }

1 个答案:

答案 0 :(得分:1)

以下是如何使用普通查询从Parse获取图像(您可以添加自己的whereKeys)...

    let query = PFQuery(className: "Your Class Name")
    query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
        if let objects = objects as? [PFObject] {
            for object in objects {
                self.imagesArray.append(UIImage(data: object["image"]!.getData()!)!)

            }

        }

    }