(iphone) force scrollViewDidEndDecelerating to be called after programmatically scrolling a view?

scrollViewDidEndDecelerating won't be called for scrollRectToVisible or setContentOffset (i.e, scrolling programmatically). If you notice the declaration of this method in the header file it clearly mentions that it's "called on finger up as we are moving".

Now, to address your issue, scrollViewDidEndScrollingAnimation delegate will be called (for setContentOffset and scrollRectToVisible), which you can use.


As you've found, scrollViewDidEndDecelerating isn't always called (if you moved a scroll view with your finger and brought it to a stop it wouldn't get called either).

Since scrollViewDidEndDecelerating is a delegate method you can force it to be called like this:

[[scrollView delegate] scrollViewDidEndDecelerating:scrollView];

I solved it by calling scrollViewDidEndDecelerating from scrollViewDidEndScrollingAnimation

-(void) scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
    [self scrollViewDidEndDecelerating:scrollView];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    //your code
}