Parse.com在Uiimage Swift中加载图像

时间:2015-07-08 19:34:09

标签: database swift parse-platform uiimageview

我已经在互联网上搜索了这个,但我无法找到一个明智的答案来回答我的问题。我只想加载存储在解析数据库中的图像(不是基于用户的) 在此先感谢,但我对此非常陌生。

我试过的代码:

    var query = PFQuery(className:"Movies")
    query.whereKey("IndexID", equalTo:StrRandomID)
    query.findObjectsInBackgroundWithBlock
        {
            (objects: [AnyObject]?, error: NSError?) -> Void in

        if error == nil {
            // The find succeeded.
            println("Successfully retrieved \(objects!.count) Objects.")
            println("RandomId = \(StrRandomID) ")

            // Do something with the found objects


            if let objects = objects as? [PFObject]
            {
                for ParseData in objects
                {
                    println(ParseData.objectId)
                    self.lblTitle.text = String(stringInterpolationSegment: ParseData["MovieName"]!)
                    self.lblYear.text = String(stringInterpolationSegment: ParseData["Year"]!)
                    self.lblRating.text = String(format: "%.1f", float_t(ParseData["IMDB_Rating"]! as! NSNumber))
                    self.lblDescription.text = String(stringInterpolationSegment: ParseData["Plot"]!)

                    let Image = ParseData["Poster"] as! PFFile
                    Image.getDataInBackgroundWithBlock
                    ({
                        (imageData: NSData!, error: NSError!) -> Void in
                        if (error == nil)
                        {
                            let imgPoster = UIImage(data: imageData)
                        }
                    })
                }
            }
        }

        else
        {
            // Log details of the failure
            println("Error: \(error!) \(error!.userInfo!)")
        }
    }

1 个答案:

答案 0 :(得分:0)

好的,所以我终于解决了它:

        if error == nil {
            // The find succeeded.
            println("Successfully retrieved \(objects!.count) Objects.")
            println("RandomId = \(StrRandomID) ")


            // Do something with the found objects

            for object: AnyObject in objects!
            {
                let Poster = object["Poster"] as! PFFile
                Poster.getDataInBackgroundWithBlock({
                    (imagedata: NSData?, error: NSError?) -> Void in
                    if (error == nil)
                    {

                        var blur = UIBlurEffect(style: UIBlurEffectStyle.Light)
                        var blurview = UIVisualEffectView(effect: blur)
                        let image = UIImage(data: imagedata!)
                        self.imgBackground.image = image
                        self.imgPoster.image = image
                        blurview.frame = self.imgBackground.bounds
                        self.imgBackground.addSubview(blurview)

                    }
                })

            }


            if let objects = objects as? [PFObject]
            {
                for ParseData in objects
                {
                    println(ParseData.objectId)
                    self.lblTitle.text = String(stringInterpolationSegment: ParseData["MovieName"]!)
                    self.lblYear.text = String(stringInterpolationSegment: ParseData["Year"]!)
                    self.lblRating.text = String(format: "%.1f", float_t(ParseData["IMDB_Rating"]! as! NSNumber))
                    self.lblDescription.text = String(stringInterpolationSegment: ParseData["Plot"]!)


                }
            }

        }