gpt4 book ai didi

swift - PFFile 作为 UIImageView

转载 作者:行者123 更新时间:2023-11-30 13:54:05 25 4
gpt4 key购买 nike

我正在使用 Parse,并且有一个名为“GolfScorecard”的类,该类有多个键,其中包括一个“scorecardImage”键,它是一个 PFFile。我正在尝试将所有高尔夫记分卡信息显示在 tableViewCell 中。我可以获取要在单元格中显示的其余记分卡类信息(例如日期、高尔夫球场名称、得分等),但我在显示记分卡图像时遇到问题。

我正在子类化 PFObject。当我查询该类时,我会将对象附加到“GolfScorecard”(子类)数组中,然后该数组包含我从 Parse 查询的所有数据。

该子类有一个 PFFile 类型的属性“scorecardImage”。有没有办法使用“getDataInBackgroundWithBlock”将 PFFile 转换为 UIImage WITHOUT?问题是,当我使用“getDataInBackgroundWithBlock”时,图像在错误的单元格中与错误的高尔夫球场名称、得分、日期等不匹配。出于某种原因,当我使用“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)

}

}

提前致谢!

-这是我设置单元 ImageView 的代码

    let pfImage = scorecardData[indexPath.row].scorecardImage

pfImage.getDataInBackgroundWithBlock({
(result, error) in

if result != nil {

cell.scorecardCellImage.image = UIImage(data: result!)

} else {

print(error)

}
})

最佳答案

我最终解决了这个问题。我将自定义单元格设为 PFTableViewCell 并将图像转换为 PFImageView。然后我使用了以下代码,该代码可以将 PFFile 转换为 UIImage,因为 PFImageView 可以接受 PFFile。这使得从 Parse 下载 PFFile 变得更加顺利。

    cell.scorecardCellImage.file = scorecardData[indexPath.row].scorecardImage
cell.scorecardCellImage.loadInBackground()

关于swift - PFFile 作为 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33884375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com