2015-01-03 77 views
2

鑄造PFFile作爲NSData的我在解析類已投入一個數組,像這樣:從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

見我的答案在這裏:http://stackoverflow.com/questions/27595220 /下載-pffile圖像從 - 解析-追加-它到陣列 - 填充 - 的UIImageView-WI/27596932#27596932 – soulshined

回答

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) 
} 
})