Iglistkit: Get cell indexPath and data via CGPoint location

Created on 20 Jan 2017  路  4Comments  路  Source: Instagram/IGListKit

Hi,

I have IGListKit with multiple sections which contain embedded IGCollectionView. I wonder how can I get master and child IndexPath from UIViewController and then get data for each IndexPath.

Thanks!

question

Most helpful comment

@shuhrat10 sure thing, should be really easy! And you don't have to use any IGListKit stuff in fact:

let path = collectionView.indexPathForItem(at: point)
let object = adapter.object(atSection: path.section)

I wonder if this would be a good API on IGListAdapter @jessesquires?

All 4 comments

@shuhrat10 sure thing, should be really easy! And you don't have to use any IGListKit stuff in fact:

let path = collectionView.indexPathForItem(at: point)
let object = adapter.object(atSection: path.section)

I wonder if this would be a good API on IGListAdapter @jessesquires?

@rnystrom I did that, but I'm getting only section. I think once I get section cell, I need to convertPoint to get IndexPath from child IGCollectionView.

Ooooh, _embedded_ collection view. I skipped over that. Here's a quick thought that might get you on the right path:

let path = collectionView.indexPathForItem(at: point)
let object = adapter.object(atSection: path.section)
if let cell = collectionView.cellForItem(at: path) as? EmbeddedCollectionViewCell,
    let sectionController = adapter.sectionController(for: object) as? HorizontalSectionController {
    let subPoint = cell.collectionView.convert(point, from: collectionView)
    let subPath = cell.collectionView.indexPathForItem(at: subPoint)
    let subObject = sectionController.adapter.object(atSection: subPath.section)
}

I'm using classes in our example project, assuming your setup is similar.

@rnystrom thank you very much! It's working as expected

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rnystrom picture rnystrom  路  3Comments

drinkius picture drinkius  路  3Comments

racer1988 picture racer1988  路  3Comments

FazeelAkhtar picture FazeelAkhtar  路  3Comments

kleiberjp picture kleiberjp  路  3Comments