Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting end of programmatic UIScrollView scroll

I'm doing programmatic scrolling in UITableViews with scrollToRowAtIndexPath, which does not trigger scrollViewDidEndDecelerating. What is a good way to detect when this scrolling has completed?

I ask because in my code:

[tableView1 scrollToRowAtIndexPath:indexPath1 atScrollPosition:UITableViewScrollPositionBottom animated:YES];
[tableView2 scrollToRowAtIndexPath:indexPath2 atScrollPosition:UITableViewScrollPositionMiddle animated:YES];

// Additional methods here

occasionally the later, additional methods fire before this scrolling has completed. I'd like to use something more fool-proof than performSelector: afterDelay:.

like image 784
Growth Mindset Avatar asked Dec 29 '22 09:12

Growth Mindset


1 Answers

Have you tried scrollViewDidEndScrollingAnimation:? It may have the same issue as your other delegate method, but it's worth a shot. The docs specifically say it's called at the end of setContentOffset:animated: and scrollRectToVisible:animated:, which I have a hunch may be used to implement scrollToRowAtIndexPath:atScrollPosition:.

Edit: it's been confirmed that scrollViewDidEndScrollingAnimation: gets called at the end of scrollToRowAtIndexPath:atScrollPosition:. Thanks Ian!

like image 64
Tim Avatar answered Feb 04 '23 22:02

Tim