我正在使用Parse.com。我有一個數組(名爲「想要」objectIds,我想用它來填充每個objectId的相應圖像的UICollectionView。我不知道從哪裏開始。如何使用objectIds的Parse數組填充UICollectionView?
我試着使用一個PFQuery與Wherekey的「想要」,但我不知道要放什麼東西在‘equalTo’參數
var downloadCards = PFQuery(className: "User")
downloadCards.whereKey("Wants", equalTo:"")
downloadCards.orderByAscending("Number")
downloadCards.limit = 200
downloadCards.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
if let objects = objects as? [PFObject] {
for object in objects {
objectIds.append(object.objectId!)
parseObjects.append(object["Image"] as! PFFile)
imageNames.append(object["Number"] as! String)
imageExpansions.append(object["ExpansionNumber"] as! String)
self.collectionView.reloadData()
}
}
} else {
println("Error: \(error!) \(error!.userInfo!)")
}
}
集合視圖代碼在這裏:
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return parseObjects.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: CardsCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CardsCollectionViewCell
parseObjects[indexPath.row].getDataInBackgroundWithBlock{
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
let image = UIImage(data: imageData!)
cell.cardsImg.image = image
}
}
return cell
}