ios - UICollectionViewCell becomes hidden=YES -
i trying implement "endless scroll" uicollectionview
.
i buffering info array in this tutorial
and implementing didenddisplayingcell
of uicollectionviewdelegate
in next manner:
- (void)collectionview:(uicollectionview *)collectionview didenddisplayingcell:(uicollectionviewcell *)cell foritematindexpath:(nsindexpath *)indexpath{ if (self.galleryarray.count > 0) { nsindexpath *newindexpath = indexpath; if (self.specialheaderview.bannerview.scrolldirection == left) { newindexpath = [nsindexpath indexpathforitem:indexpath.row - 1 insection:indexpath.section]; } else if (self.specialheaderview.bannerview.scrolldirection == right) { newindexpath = [nsindexpath indexpathforitem:indexpath.row + 1 insection:indexpath.section]; } if (newindexpath.row == (self.galleryarray.count - 1)) { // user scrolling right lastly item 'fake' item 1. // reposition offset show 'real' item 1 @ left-hand end of collection view newindexpath = [nsindexpath indexpathforitem:1 insection:indexpath.section]; [self.bannercollectionview scrolltoitematindexpath:newindexpath atscrollposition:uicollectionviewscrollpositionleft animated:no]; return; } // if (scrollview.contentoffset.x == self.collectionview.frame.size.width) { if (newindexpath.row == 0) { // user scrolling left first item false 'item n'. // reposition offset show 'real' item n @ right end end of collection view newindexpath = [nsindexpath indexpathforitem:([self.galleryarray count] -2) insection:indexpath.section]; [self.bannercollectionview scrolltoitematindexpath:newindexpath atscrollposition:uicollectionviewscrollpositionleft animated:no]; } }
}
problem is, whenever didenddisplayingcell
method gets called , collection view requests cell via it's delegate cellforitematindexpath
method, cell comes hidden.
here cellforitematindexpath
implementation:
-(uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { specialbannercell *specialbannercell = (specialbannercell *)[collectionview dequeuereusablecellwithreuseidentifier:gallerycellidentifier forindexpath:indexpath]; if (specialbannercell.hidden) { } benefit *benefit = [self.galleryarray objectatindex:indexpath.row]; [specialbannercell.imagebanner setimagewithurl:[nsurl urlwithstring:benefit.imageiphoneurl] placeholderimage:[uiimage imagenamed:@"photo_loader"]]; homecoming specialbannercell;
}
what doing wrong here?
so not sure why when used uiscrollviewdelegate methods instead of didenddisplayingcell method cell not hidden anymore , works perfect.
- (void)scrollviewdidenddecelerating:(uiscrollview *)scrollview { if (self.galleryarray.count > 0) { nsindexpath *indexpath = self.currentindexpath; nsindexpath *newindexpath = indexpath; if (newindexpath.row == (self.galleryarray.count - 1)) { // user scrolling right lastly item 'fake' item 1. // reposition offset show 'real' item 1 @ left-hand end of collection view newindexpath = [nsindexpath indexpathforitem:1 insection:indexpath.section]; self.currentindexpath = newindexpath; [self.bannercollectionview scrolltoitematindexpath:newindexpath atscrollposition:uicollectionviewscrollpositionleft animated:no]; return; } if (newindexpath.row == 0) { // user scrolling left first item false 'item n'. // reposition offset show 'real' item n @ right end end of collection view newindexpath = [nsindexpath indexpathforitem:([self.galleryarray count] -2) insection:indexpath.section]; self.currentindexpath = newindexpath; [self.bannercollectionview scrolltoitematindexpath:newindexpath atscrollposition:uicollectionviewscrollpositionleft animated:no]; } }
}
ios objective-c uicollectionview uicollectionviewcell uicollectionviewdelegate
No comments:
Post a Comment