swiftyboi
swiftyboi

Reputation: 3221

Is there a way to find the index of a UICollectionView section?

Is there a way to find the index of a UICollectionView section?

My CollectionView is populated by arrays that are contained in a master array, and I need to select the appropriate one for the section.

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

    let collectionCell: ChecklistCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("collectionCell", forIndexPath: indexPath) as! ChecklistCollectionViewCell

    let section = //I need the index of the current section here!

    let sectionArray = allCards[section]

    collectionCell.imageCell.image = UIImage(named: sectionArray[indexPath.row])

    return collectionCell

}

Similar to how it is done here:

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

    let sectionArray = allCards[section]
    return sectionArray.count

}

Upvotes: 0

Views: 349

Answers (1)

slik
slik

Reputation: 5221

let section = allCards[indexPath.section]

Upvotes: 1

Related Questions