我使用的是Parse,我有一个名为"GolfScorecard“的类,它有几个键,其中包括一个"scorecardImage”键,它是一个PFFile。我试图让所有的高尔夫计分卡信息显示在一个tableViewCell。我可以在单元格中显示其余的记分卡类信息(如日期、高尔夫球场名称、得分等),但我在显示scorecardImage时遇到了困难。
我是PFObject的子类。当我查询这个类时,我会将对象附加到一个"GolfScorecard“(子类)数组中,该数组包含我从Parse查询的所有数据。
此子类具有一个属性"scorecardImage“,其类型为PFFile。是否有一种方法可以使用“PFFile”将UIImage 转换为不使用的?问题是当我使用"getDataInBackgroundWithBlock“时,图像在错误的单元格中与错误的高尔夫球场名称、得分、日期等不匹配。由于某种原因,当我使用"getDataInBackgroundWithBlock”方法时,所有这些信息都没有在一起。
var scorecardData = [GolfScorecard]()
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:UserLeaderboardCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UserLeaderboardCell
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM-dd-yyyy"
cell.dateCellLabel?.text = dateFormatter.stringFromDate(scorecardData[indexPath.row].date)
cell.scoreCellLabel?.text = "\(scorecardData[indexPath.row].score)"
cell.golfCourseCellLabel?.text = scorecardData[indexPath.row].golfCourse
return cell
}
//THIS IS MY QUERY
func loadUserScorecardData() {
scorecardData.removeAll()
let query = GolfScorecard.query()
query!.whereKey("golfer", equalTo: PFUser.currentUser()!)
query!.findObjectsInBackgroundWithBlock { (scorecards: [PFObject]?, error: NSError?) -> Void in
if error == nil {
for object:PFObject in scorecards! {
if let object = object as? GolfScorecard {
self.scorecardData.append(object)
print(self.scorecardData)
print(self.scorecardData.count)
}
}提前谢谢!
-HERE是我用来设置单元格IMAGEVIEW的代码
let pfImage = scorecardData[indexPath.row].scorecardImage
pfImage.getDataInBackgroundWithBlock({
(result, error) in
if result != nil {
cell.scorecardCellImage.image = UIImage(data: result!)
} else {
print(error)
}
})发布于 2015-11-27 00:20:41
我最终解决了这个问题。我将我的自定义单元格设置为PFTableViewCell,并将图像转换为PFImageView。然后,我使用了以下代码,它可以将PFFile转换为UIImage,因为PFImageView可以接受PFFile。这使得从Parse下载PFFile变得更加顺畅。
cell.scorecardCellImage.file = scorecardData[indexPath.row].scorecardImage
cell.scorecardCellImage.loadInBackground()https://stackoverflow.com/questions/33884375
复制相似问题