0

everyone.

Is there a way to get a callback when tableView.scrollToRow(...) or tableView.setContentOffset(...) animation completed?

Please read the whole question ↓ not only the title :)

I know about delegate method scrollViewDidEndScrollingAnimation and it doesn't work in my case: I have a few different calls of scrollToRow(...) and need to execute the proper block of code after each. Thus, using scrollViewDidEndScrollingAnimation(...) will cause overcomplicated logic.

I also know about wrapping tableView.scrollToRow(...) into a UIView.animate() which has callback closure. But in this case, tableView doesn't generate delegate event of scrollViewDidScroll(...) which I listen to for proper interface updates.

That's why I'm digging in the direction of having a callback after regular tableView.scrollToRow(...). Is there a way to get what I need?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Anton Lovchikov
  • 473
  • 1
  • 3
  • 13
  • You can check with UIScrollView delegate methods. They will call once you call tableView.scrollToRow(...) or tableView.setContentOffset(...) methods. – Surjeet Singh Apr 13 '17 at 12:05
  • You can use all scrollView delegate methods – Sivajee Battina Apr 13 '17 at 12:08
  • func scrollViewDidScroll(_ scrollView: UIScrollView!) is the main method through which you can achieve your requirement – Sivajee Battina Apr 13 '17 at 12:10
  • 1
    @SivajeeBattina Delegate-based solution won't work. From [Apple docs](https://developer.apple.com/reference/uikit/uitableview/1614997-scrolltorow#discussion): *Invoking this method does not cause the delegate to receive a scrollViewDidScroll(_:) message*. – Paulo Mattos Apr 13 '17 at 12:11
  • @SivajeeBattina as I wrote in the question, I'd like to avoid using delegate methods. – Anton Lovchikov Apr 13 '17 at 12:29

0 Answers0