9

I am using scrollViewDidScroll delegate in my application.

But, many times, even though I dint start scrolling, this delegate is getting invoked which is creating a lot of problem. I heard that even when contentSize for a particular scroll view is set then at that time also this delegate i.e., scrollViewDidScroll will invoke.

What are the different scenarios in which this delegate gets invoked. What are the steps to control this?

Can I set any parameter to handle this?

Bharath
  • 2,911
  • 6
  • 30
  • 62

5 Answers5

9

To prevent scrollDidScroll: from firing automatically when the view is loaded and adjusted, I waited to add my UIScrollView delegate until after all the views load using viewDidLayoutSubviews. It is working well for me.

- (void)viewDidLayoutSubviews {
    // add table view delegate after the views have been laid out to prevent scrollViewDidScroll
    // from firing automaticly when the view is adjusted on load, which makes the tab bar disappear 
    self.tableView.delegate = self;
} 
Iulian Onofrei
  • 8,409
  • 9
  • 67
  • 106
Sev
  • 875
  • 1
  • 13
  • 32
5

relevant

scrollViewDidScroll: gets called every time the scroll bounds change. This means it gets called during the scroll, as well as when it starts. You may want to try scrollViewWillBeginDragging: instead.

Community
  • 1
  • 1
Dima
  • 23,268
  • 5
  • 53
  • 82
4

scrollViewDidScroll also gets invoked when the orientation changes. This I came to know from here. This was the problem I was facing. And now my problem solved with this post.

Community
  • 1
  • 1
Bharath
  • 2,911
  • 6
  • 30
  • 62
3

Hi Guys its very old question, however, if you wanna know if the scrollDidScroll was triggered manually(through finger) or its due to other event like didSelect or setContentOffset, use the UIScrollView.isTracking property.

LundinCast
  • 8,746
  • 4
  • 36
  • 46
1

Set UICollectionView, UITableView delegate here in this method

override func viewDidLayoutSubviews() {
     super.viewDidLayoutSubviews()
     // This method is called only after all subviews are laid
}
Karthik damodara
  • 1,751
  • 18
  • 17