将indexPath公开给configureCell

时间:2018-03-09 00:36:24

标签: xlpagertabstrip

目前,configureCell只能访问单元格和IndicatorInfo。在我的用例中,我想知道单元格的indexPath,以便我知道我正在配置哪个单元格并进行相应的自定义。具体来说,我们希望第一个单元格(indexPath 0)显示与其他单元格略有不同。

IndicatorInfo目前是一个结构体,因此我不能将其子类化以添加另一个字段来存储indexPath。

1 个答案:

答案 0 :(得分:0)

只需更改configureCell()的定义,并在集合视图的cellForItemAt函数中调用它时为其添加indexPath:

collectionView(_ collectionView:UICollectionView,cellForItemAt indexPath:IndexPath) - > UICollectionViewCell

所以基本上,请按照以下步骤操作:

  1. 转到档案 - > ButtonBarPagerTabStripViewCOntroller.swift
  2. 查找 configureCell()功能。
  3. indexPath:IndexPath 添加为定义
  4. 中的参数之一
  5. 检查configureCell()的用法并在函数调用中传递indexpath。
  6. 当您开始编辑此文件时,它会要求您解锁它。您必须在提示中允许它。
  7. 现在当你覆盖configureCell()函数时,它也会为你提供indexPath。
  8. 参考以下截图: enter image description here

相关问题