ios - Change UINavigationbar title according to UICollectionView Cell -


im trying change title of uinavigationbar title according uicollectionview cell indexpath.row, have horizontal uicollectionview cells photo sliding-content (as photo app in ios).

what trying achieve when move indexpath.row example 1 2 change title having 1 issue, i've placed following code in cellforitematindexpath or willdisplaycell :

self.title = "\(indexpath.row+1) of 2" 

this code works fine has 1 issue, when start dragging next cell return i, title changed 2 still in 1 ! annoying !

i've tried place code in scrollviewdidenddecelerating has same issue, started dragging changed mind stay on cell 1 method says okey end dragging, title again changes 2 still in one.

i need since if still don't have change title, if in next cell change title.

it happening because method cellforitematindexpath called prepare second item, first cell still in memory , method cellforitematindexpath not called when return first. try this:

-(void)scrollviewdidenddecelerating:(nonnull uiscrollview *)scrollview {         float currentpage = self.collectionview.contentoffset.x / self.collectionview.frame.size.width;         nslog(@"current page: %f", ceil(currentpage)); } 

don't forget add uiscrollviewdelegatein collectionviewcontroller.h


Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -