PFFile未被检测到

时间:2015-07-25 23:20:18

标签: ios parse-platform swift2 xcode7

所以我正在设置一个UITableViewController来从Parse中检索图像文件,但是我遇到了一些问题。我相信它与dataDelegate或dataSource有关,但不确定......非常感谢帮助!

import UIKit
import Parse


class HomeTableViewController: UITableViewController {

    var albumImageFiles = [PFFile]()
    var imageText = [String]()

    override func viewDidLoad() {
        super.viewDidLoad()


        // Do any additional setup after loading the view.
        let query = PFQuery(className: "Posts")
        query.orderByDescending("createdAt")
        query.findObjectsInBackgroundWithBlock { (posts:[AnyObject]?, error: NSError?) -> Void in

            if error == nil {
                //success fetching objects


                for post in posts! {
                    self.albumImageFiles.append(post["imageFile"] as! PFFile)
                    self.imageText.append(post["albumText"] as! String)


                }


                /*reload the table*/
                //self.reloadData()



            } else {
                print(error)

            }

        } 

//table view cell amounts
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return albumImageFiles.count

}


//
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let homeCell: HomeTableViewCell = tableView.dequeueReusableCellWithIdentifier("HomeCell") as! HomeTableViewCell

    //text
    homeCell.imageLabel.text = imageText[indexPath.row]

    //images
    albumImageFiles[indexPath.row].getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -> Void in

        if imageData != nil {
            let image = UIImage(data: imageData!)
            homeCell.albumImage.image = image


        } else {
            print(error)

        }

    }


    return homeCell


}

0 个答案:

没有答案