Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用ObjectId的解析数组填充UICollectionView?_Ios_Swift_Parse Platform - Fatal编程技术网

Ios 如何使用ObjectId的解析数组填充UICollectionView?

Ios 如何使用ObjectId的解析数组填充UICollectionView?,ios,swift,parse-platform,Ios,Swift,Parse Platform,我正在使用Parse.com。我有一个objectId数组(名为“Wants”),我想用每个objectId对应的图像填充UICollectionView。我不太确定从哪里开始 我尝试使用Wherekey为“Wants”的PFQuery,但我不确定在“equalTo”参数中输入什么 var downloadCards = PFQuery(className: "User") downloadCards.whereKey("Wants", equalTo:"")

我正在使用Parse.com。我有一个objectId数组(名为“Wants”),我想用每个objectId对应的图像填充UICollectionView。我不太确定从哪里开始

我尝试使用Wherekey为“Wants”的PFQuery,但我不确定在“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
}

是的,你可以,但是功能

// Initialise the PFQueryTable tableview
override init!(style: UITableViewStyle, className: String!) {
    super.init(style: style, className: className)
}

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)

    // Configure the PFQueryTableView
    self.parseClassName = "yourClass"

    self.textKey = "yourObject"
    self.pullToRefreshEnabled = true
    self.paginationEnabled = false
}
是异步的,因此collectionView函数返回空单元格。最简单的方法是下载所有数据,然后更新集合视图,而不是使用whereKey(key:equal:to)使用whereKeyExists(key)。这将返回具有数组的所有对象

downloadCards.whereKeyExists("Wants")