swift - 如何快速获取 Collection View 的标题?

标签 swift uicollectionview uicollectionviewdelegate

如何在 DidSelectItemAtIndexPath 上获取 Collection View 的标题,以便在选择项目时更改标题的文本。

最佳答案

您可以使用:

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

关于swift - 如何快速获取 Collection View 的标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41180139/

相关文章:

arrays - 从indexpath.row中的数组获取特定值

ios - 如何在 iOS 8/Swift 中处理带有屏幕尺寸/方向变化的 NSLayoutConstraints?

swift - 将自定义参数传递给 uibutton #selector swift 3

ios - 滚动时 uicollectionviewcell 中的图像加载错误

ios - 使用委托(delegate)模式的选择器无效

iOS Swift CollectionView 委托(delegate)未被调用

ios - 使用 let 或 var 关键字创建类对象?

ios - 由于未捕获的异常 'NSInternalInconsistencyException' 而终止应用程序,原因 : 'Invalid parameter not satisfying: indexPath != nil'

ios - 按单元格而不是屏幕分页 UICollectionView

swift - 编译器说我不符合 UICollectionViewDelegate;与实际使用冲突