如何快速获取集合视图的标题?

Raj*_*tal 0 uicollectionview uicollectionviewdelegate swift

如何在DidSelectItemAtIndexPath上获取集合视图的Header,以便在选择项目时更改header的文本。

Jim*_*mes 5

您可以使用:

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){
    let indexHeaderForSection = NSIndexPath(row: 0, section: indexPath.section) // Get the indexPath of your header for your selected cell
    let header = collectionView.viewForSupplementaryElementOfKind(indexHeaderForSection)
}
Run Code Online (Sandbox Code Playgroud)