[英]Parse Image -> UITableViewCell Not Displaying (Swift)
I'm struggling to get an image stored in Parse to display in my UITableViewCell
. 我正在努力获取存储在Parse中的图像以显示在UITableViewCell
。 The cell is being populated from other data stored in the Parse object (name, etc) - just the image isn't displaying correctly. 该单元格是由存储在Parse对象中的其他数据(名称等)填充的-只是图像显示不正确。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Cell")
cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
if let client: PFObject = self.clientList[indexPath.row] as? PFObject {
let forename: String = client["forename"] as! String
let surname: String = client["surname"] as! String
let fullname: String = forename + " " + surname
cell.textLabel?.text = fullname
cell.detailTextLabel?.text = client.objectId
let userImageFile = client["image"] as? PFFile
if let imageFile = userImageFile {
println(imageFile)
imageFile.getDataInBackgroundWithBlock({ (imageData: NSData?, error: NSError?) -> Void in
if error == nil {
if let imageData = imageData {
self.image = UIImage(data: imageData)!
}
}
})
// THIS DOESN'T DISPLAY AN IMAGE WHEN RUN
cell.imageView?.image = image
} else {
// THIS IS A LOCAL IMAGE DISPLAYED IF THE PARSE OBJECT DOESN'T CONTAIN AN IMAGE FILE. THIS DOES DISPLAY CORRECTLY WHEN CALLED.
let image = UIImage(named: "userMale")
cell.imageView?.image = image
println("Local Image")
}
}
cell.imageView?.layer.cornerRadius = 40
cell.imageView?.layer.masksToBounds = true
cell.imageView?.layer.borderColor = UIColor.lightGrayColor().CGColor
cell.imageView?.layer.borderWidth = 1
return cell
}
Your background retrieval is not complete when you plug it in as shown 'cell.imageView?.image = image'. 当您插入背景时,如“ cell.imageView?.image = image”所示,背景检索尚未完成。 You need to use a post a notification and after the background is done and then set the cell after you receive the notification. 您需要在发布后使用通知,并在完成后台操作后,在收到通知后设置单元格。 If you do a println on the image just before you assigne it to the cell you will find that it shows a size of 0 by 0. An example of notification is in my example code in example 如果您在图像上做一个println你它assigne到细胞之前,你会发现,它显示了一个大小为0 0.通知一个例子是在我的示例代码示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.