我在Parse中有一个类,它被放入一个数组中,如下所示:
// PFQuery to get all Events
var GetAllEvents : PFQuery = PFQuery(className: "Types_")
GetAllEvents.findObjectsInBackgroundWithBlock{
(objects:[AnyObject]!, error:NSError!) ->Void in
if (error == nil) {
for object in objects {
self.EventData.addObject(object)
println(object)
self.tableView.reloadData()
}
}else
{
println("Error \(error)")
}
}
我试图把结果放到一个tableview中,这对字符串很好,但是对于图像我真的很挣扎。
cell.EventTitle.text = (event.objectForKey("Title") as String!)
cell.EventType.text = (event.objectForKey("TypeOfVenue_") as String!)
var image = UIImage(data: (event.objectForKey("TypeImage"))! as NSData)
所以当我尝试为图像创建变量时 - 它只是崩溃,任何想法?
答案 0 :(得分:3)
PFFile
无法投放到NSData
,您需要做的是使用方法getData
来检索NSData
:
let file = event["TypeImage"]
file.getDataInBackgroundWithBlock({ (data, error) -> Void in
if let data = data where error == nil{
var image = UIImage(data: data)
}
})