0

在这里,我使用facetfiltersfrom given过滤了数据,facets并在搜索查询函数中获取了数据,并且响应已传递给如下所示的模型类,并且在集合视图func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath, containing hit: [String : Any]) -> UICollectionViewCell中,正在检索的委托命中数据是默认索引数据,过滤后的数据没有进入命中可以任何人都可以帮助我如何将这些数据传递给 swift 3 中的集合视图?

下面是我已经尝试过的代码

if (self.appId != nil && self.apiKEY != nil && self.Indices != nil) {
        InstantSearch.shared.configure(appID: "\(self.appId!)", apiKey: "\(self.apiKEY!)", index: "\(self.Indices!)en_products")
        InstantSearch.shared.params.attributesToRetrieve = ["*"]
        InstantSearch.shared.registerAllWidgets(in: self.view)
        if receivedText != nil {
            print(String(describing: receivedText!))
            InstantSearch.shared.searchBar(searchBar, textDidChange: receivedText!)
            InstantSearch.shared.params.attributesToRetrieve = ["*"]
            InstantSearch.shared.registerAllWidgets(in: self.view)
        }else {
            let query = Query()
            query.facets = facetsArray
            print(categoriesArray)
            query.facetFilters = categoriesArray
            query.hitsPerPage = 100
            InstantSearch.shared.searcher.index.search(query, requestOptions: nil, completionHandler: { (data, error) in
                self.lastResults = SearchHits(fromDictionary: data!)
                print(data)
                self.listCollectionView.reloadHits()
            })
        }
        hitsCollectionViews = [self.listCollectionView]
        ActivityIndicator.stopAnimating()
    }
open override func collectionView(_ collectionView: UICollectionView,
                                  cellForItemAt indexPath: IndexPath,
                                  containing hit: [String : Any]) -> UICollectionViewCell {
    //        print(hit)
    let cell: listItemCollectionViewCell
    cell = collectionView.dequeueReusableCell(withReuseIdentifier: "hitCell", for: indexPath) as! listItemCollectionViewCell
    cell.listItemLabel.text = hit["name"] as? String
    cell.listItemPrice.text = hit["price"] as? String
    if let strImage = hit["image_url"] as? String {
        let baseUrl = "http:\(strImage)"
        cell.listItemImg.contentMode = .scaleAspectFit
        cell.listItemImg.kf.indicatorType = .activity
        if URL(string: baseUrl) != nil {
            let resource = ImageResource(downloadURL: URL(string: baseUrl)!, cacheKey: baseUrl)
            cell.listItemImg.kf.setImage(with: resource, placeholder: nil, options: nil, progressBlock: nil, completionHandler: nil)
        }
        else{
            cell.listItemImg.image = #imageLiteral(resourceName: "placeholder")
        }
    }
    cell.wishListButton.addTarget(self, action: #selector(saleTappedButton(sender:)), for: .touchUpInside)
    cell.listItemStarRating.starBorderColor = UIColor.lightGray
    cell.listItemStarRating.starBorderWidth = 0.5
    return cell
}
4

0 回答 0