从Parse中检索Image,String和Int

时间:2016-01-18 17:12:29

标签: ios swift parse-platform

我必须从Parse检索图像,我正在处理这段代码:

class ViewControllerHome: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var MessageTable: UITableView!

    let color = UIColor(red: 0.0/255.0, green: 105.0/255.0, blue: 92.0/255.0, alpha: 1)
    let colore = UIColor.whiteColor()
    let coloree = UIColor(red: 33.0/255.0, green: 33.0/255.0, blue: 33.0/255.0, alpha: 1)

        var Username = [String]()
        var Image = [PFFile]()
        var Likes = [Int]()

    override func viewDidLoad() {
        super.viewDidLoad()

        var refreshControl = UIRefreshControl()
        refreshControl.addTarget(self, action: Selector("refreshPulled"), forControlEvents: UIControlEvents.ValueChanged)

        loadData()
        self.MessageTable.reloadData()

        self.navigationController?.navigationBar.barTintColor = color
        self.navigationController?.navigationBar.tintColor = colore
        self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: colore]
        UITabBar.appearance().barTintColor = coloree
        UITabBar.appearance().tintColor = colore
        UITabBar.appearance().translucent = false

        self.MessageTable.delegate = self
        self.MessageTable.dataSource = self

        func refreshPulled() {

            loadData()
            self.MessageTable.reloadData()

            refreshControl.endRefreshing()

        }
    }

    func loadData() {

        let query = PFQuery(className: "Messages")
        query.orderByDescending("createdAt")
        query.findObjectsInBackgroundWithBlock {
            (posts: [PFObject]?, error: NSError?) -> Void in

            if (error == nil) {

                if let posts = posts as [PFObject]? {
                    for post in posts{

                        self.Image.append(post["Post"] as! PFFile)
                        self.Username.append(post["Name"] as! String)
                        self.Likes.append(post["Vote"] as! Int)

                    }
                }
            }
        }
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = self.MessageTable.dequeueReusableCellWithIdentifier("cell")! as! TableViewCellHome

        var imagesToLoad = self.Image[indexPath.row] as PFFile
        var imagesUser = self.Username[indexPath.row] as String
        var imageLikes = self.Likes[indexPath.row] as Int

        //This line gives me an error: call can throw, but is not marked with 'try' and the error is not handled
        var imagesdata = imagesToLoad.getData()
        var finalizedImage = UIImage(data: imagesdata)

            cell.PostImage.image = finalizedImage
            cell.UsernameLabel.text = imagesUser
            cell.LikesLabel.text = "\(imageLikes)"

        return cell
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return Username.count
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

    }
}

此代码应该从parse的后端获取并显示Image,string和Int Value。问题是没有显示任何内容。如何更改代码以便正确显示?该行还有一个错误:

var imagesdata = imagesToLoad.getData()

这一行告诉我

  

电话可以扔,但没有标记'尝试'并且没有处理错误

提前感谢任何可以帮助我解决此问题的人。

0 个答案:

没有答案