gpt4 book ai didi

swift - 解析 PFQueryTableViewConntroller 不加载图像

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

我正在使用 parse 的 PFQueryTableViewController,在检索日期时,一切似乎都工作正常,除了 UIImageView 没有加载数据库中的文件。加载文本和其他所有内容(文件除外)。这是我的代码:

import UIKit
import Parse
import ParseUI

class PostsTableViewController: PFQueryTableViewController {

override func queryForTable() -> PFQuery {

let query = PFQuery(className: "Posts")
query.cachePolicy = .CacheElseNetwork
query.orderByDescending("createdAt")
return query
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {

let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! PostsTableViewCell

let posterUsernameText = object?.objectForKey("createdBy") as? String
cell.posterUsername.setTitle("\(posterUsernameText)", forState: .Normal)

cell.msgTextView.text = object?.objectForKey("text") as? String

let imageFile = object?.objectForKey("image") as? PFFile
cell.cellImageView.file = imageFile
cell.imageView?.loadInBackground()

return cell

}

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

if indexPath.row + 1 > self.objects?.count {

return 44

}

let height = super.tableView(tableView, heightForRowAtIndexPath: indexPath)
return height
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

if indexPath.row + 1 > self.objects?.count {

self.loadNextPage()
tableView.deselectRowAtIndexPath(indexPath, animated: true)

} else {

self.performSegueWithIdentifier("showDetail", sender: self)

}
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

if segue.identifier == "showDetail" {



}

}

}

enter image description here

最佳答案

我认为你应该更改此代码:

let imageFile = object?.objectForKey("image") as? PFFile
cell.cellImageView.file = imageFile
cell.imageView?.loadInBackground()

致:

if let imageFile = object?.objectForKey("image") as? PFFile {
imageFile.getDataInBackgroundWithBlock({ (imgContent:NSData?, error:NSError?) -> Void in
if error != nil {
print(error?.description)
}else if let imgContent = imgContent {
cell.imageView?.image = UIImage(data: imgContent)!
}
})
}

关于swift - 解析 PFQueryTableViewConntroller 不加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34670350/

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