giulio92 / GLTableCollectionView

Netflix and App Store like UITableView with UICollectionView, written in pure Swift 4.2
MIT License
705 stars 37 forks source link

How to get "indexPath.section" in a UICollectionView? #16

Closed dkmczk closed 7 years ago

dkmczk commented 7 years ago

Thank you for the great project!! When I tapped a collectionView, how can I get "indexPath.section"? I could get indexPath.item but indexPath.section always returns "0".

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { print(indexPath.section) print(indexPath.item) }

Thank you!

giulio92 commented 7 years ago

Hello @dkmczk,

To get the indexPath for a given UICollectionView you should rely on the UITableView delegate instead of the UICollectionView one, since you would have a UICollectionView for each UITableView section, and every collection is separated from the other one. You would have a UICollectionView indexPath.section greather than "0" only in the case you would have two UICollectionView inside a given UITableView section

dkmczk commented 7 years ago

Thank you so much I understood! I will use UITableView delegate instead.