ios - Is there a way to determine the order of the self.collectionview.visiblecells? -
on collection view, know first item that's being displayed on collection view. figured @ visiblecells , first item on list, it's not case.
returning first item visible on collectionview:
uicollectionviewcell *cell = [self.collectionview.visiblecells firstobject];
returning first item from items in collectionview
uicollectionviewcell *cell = [self.collectionview cellforitematindexpath:[nsindexpath indexpathforitem:0 insection:0]];
you don't want cell, data:
nsindexpath *indexpath = [[self.collectionview indexpathsforvisibleitems] firstobject]; id yourdata = self.datasource[indexpath.row];
but visivlecells array not ordered!!
well, need order it:
nsarray *indexpaths = [self.collectionview indexpathsforvisibleitems]; nssortdescriptor *sort = [nssortdescriptor sortdescriptorwithkey:@"row" ascending:yes]; nsarray *orderedindexpaths = [indexpaths sortedarrayusingdescriptors:@[sort]]; // orderedindexpaths[0] return position of first cell. // can cell or data datasource accessing .row
edit: believe visiblecells (and like) return ordered already, didn't find regarding on docs. added ordering part make sure.
Comments
Post a Comment