如何在swift中获取集合视图的标题?

问题描述:

如何获取DidSelectItemAtIndexPath上集合视图的标题,以便在选择项目时更改标题的文本。如何在swift中获取集合视图的标题?

由于iOS的9,你可以使用:

func supplementaryView(forElementKind elementKind: String, 
       at indexPath: IndexPath) -> UICollectionReusableView? 

度日指数路径的补充视图。

退房Apple's documentation

您可以使用:

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) 
} 
+0

是的,我得到头的didSelectItemAtIndexPath但收集滚动视图时,那之后选择任何项目,然后它给空值,而不是头。因为我觉得这部分不在队列中。 –

+0

这很正常,您的标题不可见! –

+0

你有什么想法,那是什么解决方案? –