我正在嘗試將Parse.com中的文本圖像查詢到我的UICollectionView。這是我的代碼:從Parse.com查詢到UICollectionView
func QueryFromParse(){
var query = PFQuery(className: "Posts")
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]?, error:NSError?) -> Void in
if error == nil
{
if let newObjects = objects as? [PFObject] {
for oneobject in newObjects {
let text = oneobject["imageText"] as! String
let username = oneobject["username"] as! String
let time = oneobject.createdAt!
let placeholder = UIImage(named: "Placeholder")! // Put some placeholder image here till the other image downloads.
var OneBigObject = Details(username: username, text: text, CreatedAt: time, image: placeholder)
self.arrayOfDetails.append(OneBigObject)
dispatch_async(dispatch_get_main_queue()) { self.collectionView.reloadData() }
let userImageFile = oneobject["imageFile"] as! PFFile
userImageFile.getDataInBackgroundWithBlock({ (imageData:NSData?, error:NSError?) -> Void in
if error == nil {
if let newImage = UIImage(data: imageData!) {
OneBigObject.image = newImage
dispatch_async(dispatch_get_main_queue()) { self.collectionView.reloadData() }
}
}
})
}
}
}
}
}
struct Details {
var username:String!
var text:String!
var CreatedAt:NSDate!
var image:UIImage!
init(username:String,text:String,CreatedAt:NSDate,image:UIImage){
self.username = username
self.text = text
self.CreatedAt = CreatedAt
self.image = image
}
}
的圖像並僅顯示 「佔位符」 的形象,而不是從Parse.com圖像,但圖像文字和時間是正確的...任何建議?
你可以把詳細信息類的代碼 – Lamar
@Lamar - 在問題中添加。 –