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

symfony - InvalidConfigurationException in SecurityExtension.php line 429: No authentication listener registered for firewall "secured_area" -

angular ui router - 10 digest iterations reached in angularjs when using $state.go -

javascript - Handling constructor related functions while testing with mocha and sinon -