你应该看看PFImageView的功能loadInBackground()
。
例如,如果您使用的是PFTableViewController与PFTableViewCell,你可以做以下
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("CustomCell") as! CustomTableViewCell!
if cell == nil {
cell = CustomTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "CustomCell")
}
if let name = object?["name"] as? String {
cell.nameLbl.text = name
}
var initialThumbnail = UIImage(named: "placeholder")
cell.imgView.image = initialThumbnail
if let thumbnail = object?["photo"] as? PFFile {
cell.imgView.file = thumbnail
cell.imgView.loadInBackground()
}
return cell
}
与PFTableViewCell有
class CustomCell: PFTableViewCell {
@IBOutlet weak var nameLbl: UILabel!
@IBOutlet weak var imgView: PFImageView!
}
从另一个SO
reply
此外,你可以试试这个:
let userImageFile = userPhoto["imageFile"] as PFFile
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData!, error: NSError!) -> Void in
if !error {
let image = UIImage(data:imageData)
}
}
谢谢!这有助于很多! –