Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.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 如何在屏幕外滚动时访问CollectionView标题(即不可见)_Ios_Swift_Uicollectionview - Fatal编程技术网

Ios 如何在屏幕外滚动时访问CollectionView标题(即不可见)

Ios 如何在屏幕外滚动时访问CollectionView标题(即不可见),ios,swift,uicollectionview,Ios,Swift,Uicollectionview,我的CollectionView标题中有图像,希望在单击按钮时访问它们 我用过 let cell = collectionView(collectionView, viewForSupplementaryElementOfKind: UICollectionView.elementKindSectionHeader, at: headerIndexPath) as? ListItemHeaderReusableView 但是这行代码重新加载了头的override func,我不想这样做,因为

我的CollectionView标题中有图像,希望在单击按钮时访问它们

我用过

 let cell = collectionView(collectionView, viewForSupplementaryElementOfKind: UICollectionView.elementKindSectionHeader, at: headerIndexPath) as? ListItemHeaderReusableView
但是这行代码重新加载了头的override func,我不想这样做,因为图像会从头中删除

也试过

 let ncell = collectionView.supplementaryView(forElementKind: UICollectionView.elementKindSectionHeader, at: indexPath) as? ListItemHeaderReusableView
出于某种原因,它在模拟器上返回单元格,但在设备上返回nil


当标题不可见且内容未重新加载时,如何访问标题。

您可以将标题保留为属性

class ViewController: UIViewController {

    let header = ListItemHeaderReusableView()

     //  here is your custom collectionView header
     //  you have it as a property
     //  so you retain it, it will not be reloaded when you scroll

}

extension ViewController: UICollectionViewDataSource{

    func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
        // do some custom config
        return header
    }


    // more methods
}

你能解释一下你所说的“访问”是什么意思吗?所谓访问,我指的是当标题滚动到屏幕外时应用到标题上的访问图像。