如何在DidSelectItemAtIndexPath上获取集合视图的标题,以便在选择项目时更改标题文本。
答案 0 :(得分:4)
您可以使用:
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)
}
答案 1 :(得分:3)
从iOS 9开始,您可以使用:
func supplementaryView(forElementKind elementKind: String,
at indexPath: IndexPath) -> UICollectionReusableView?
通过索引路径获取补充视图。