Создание представления представления viewForSupplementaryElementOfKind выполняется первым - PullRequest
0 голосов
/ 15 февраля 2019

У меня есть код для 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) запустить первым

...