【发布时间】:2016-03-23 10:38:12
【问题描述】:
我将图像作为 PFFile。但是当每次 PFFile 下载时我的表格都在滚动并且需要时间。 我想缓存我的文件,所以如果要下载它,那么它将从缓存中获取,而不是从 Parse 获取。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("cell") as! RidesCustomCell!
if cell == nil {
cell = RidesCustomCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
}
let currentDic = dataArray.objectAtIndex(indexPath.row) as! NSDictionary
cell.backgroundColor = UIColor.clearColor()
cell.txtName.text = currentDic.valueForKey("firstName") as? String
cell.txtPrice.text = currentDic.valueForKey("price") as? String
cell.txtTime.text = currentDic.valueForKey("date")as? String
cell.txtFrom.text = currentDic.valueForKey("from") as? String
cell.txtTo.text = currentDic.valueForKey("to") as? String
print(currentDic)
cell.imgUser.image = UIImage(named: "noImg.png")
if (currentDic.valueForKey("imageFile") != nil){
// let userImageFile = currentDic.valueForKey("imageFile") as! PFFile
let queue : dispatch_queue_t = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
dispatch_async(queue, { () -> Void in
print(currentDic)
let pfuserGet = currentDic.valueForKey("user") as! PFUser
print(pfuserGet.username)
print(pfuserGet.email)
print(pfuserGet.password)
let userImageFile = pfuserGet.objectForKey("profilePicture") as! PFFile
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
if let imageData = imageData {
let image = UIImage(data:imageData)
cell.imgUser.image = image
}
}
}
})
}
return cell;
}
【问题讨论】:
-
你能添加你的 cellForRowAtIndexPath 吗?你使用的是 PFQueryTableViewController 还是 UITableViewController?
-
我正在使用 UITableViewController
-
你能把你的代码附加到 cellForRoAtIndexPath
-
你在哪里有 PFQuery?如果您添加代码,我可以帮助您
-
检查更新的代码
标签: swift image caching parse-platform pffile