使集合视图viewForSupplementaryElementOfKind首先运行

时间:2019-02-15 08:13:38

标签: iphone uicollectionview ios9 uicollectionviewcell

我有一些用于collectionView的代码 这是代码

func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {

    guard kind == UICollectionElementKindSectionHeader else {
        return UICollectionReusableView()
    }
    let view = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "Section", for: indexPath) as! section

    if searchActive == true {
        view.textLabel.text == ""
        //reload data inside cellForItemAt indexPath: IndexPath

    } else {
        //header section
        view.textLabel.text = categoryList[indexPath.section]
        //reload data inside cellForItemAt indexPath: IndexPath
    }
    return view

}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    //row section
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! CollectionCell

    let cellHeader = collectionView.dequeueReusableCell(withReuseIdentifier: "Section", for: indexPath) as! section

    print (cellHeader.textLabel.text)

    if searchActive == true {

        _ = kingdomListArray.filter { (dic) -> Bool in

            if filteredTableData[indexPath.row] == dic.sub_Category_Data {

                cell.textLabel.text = dic.sub_Category_Data


            }
            return true
        }
        return cell
    } else {

            _ = kingdomListArray.filter { (dic) -> Bool in
                    if subCategoryList[indexPath.row] == dic.sub_Category_Data {

                        cell.textLabel?.text = dic.sub_Category_Data

                    }
                return true
        }
        return cell
    }
}

在此代码中,func collectionView(viewForSupplementaryElementOfKind)用于显示collection view内部的节标题,而问题是,func collectionView(viewForSupplementaryElementOfKind)将在func collectionView(cellForItemAt indexPath: IndexPath)之后运行

我想检测func collectionView(viewForSupplementaryElementOfKind中标头中的名称,然后为func collectionView(cellForItemAt indexPath: IndexPath)中每个标头名称过滤每个数据。

如何首先运行func collectionView(viewForSupplementaryElementOfKind)

0 个答案:

没有答案