how to check when UITableView is done scrolling

22,012

Solution 1

You would implement UIScrollViewDelegate protocol method as follows:

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    if (!decelerate) {
        [self scrollingFinish];
    }
}

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

- (void)scrollingFinish {
    //enter code here
}

Swift version

public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
    if decelerate {
        scrollingFinished()
    }
}

public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    scrollingFinished()
}

func scrollingFinished() {
    print("scrolling finished...")
}

For the above delegate method The scroll view sends this message when the user’s finger touches up after dragging content. The decelerating property of UIScrollView controls deceleration. When the view decelerated to stop, the parameter decelerate will be NO.

Second one used for scrolling slowly, even scrolling stop when your finger touch up, as Apple Documents said, when the scrolling movement comes to a halt.

Solution 2

The below code will update you every time when user scrolling stopped.

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    if (!decelerate)
    {
        if (isScrollingStart)
        {
            isScrollingStart=NO;
            [self scrollingStopped];
        }
    }
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{

    if (isScrollingStart)
    {
        isScrollingStart=NO;
        [self scrollingStopped];
    }
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    isScrollingStart=YES;
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    isScrollingStart=YES;
}
-(void)scrollingStopped
{
    NSLog(@"Scrolling stopped");
}

Solution 3

UITableView conforms to UIScrollViewDelegate. Please, refer to the documentation of that protocol, it has methods you need.

Share:
22,012

Related videos on Youtube

sankaet
Author by

sankaet

Updated on July 09, 2022

Comments

  • sankaet
    sankaet almost 2 years

    Is there a way to check if my tableview just finished scrolling? table.isDragging and table.isDecelerating are the only two methods that I can find. I am not sure how I can either anticipate or get notified when the tableview finishes scrolling.

    Can I somehow use timers to check every second if the tableView is scrolling or not?

  • oyalhi
    oyalhi over 8 years
    Works very nicely, thank you. The value isScrollingEnd is written but never used. Is there just in case you need to use it? Did you meant to check it in scrollingStopped?
  • Pandey_Laxman
    Pandey_Laxman over 8 years
    Updated ans. , there is no use of isScrollingEnd here :)
  • Jovan Stankovic
    Jovan Stankovic almost 7 years
    User can also invoke table scroll by tapping the top of the screen. Unfortunately, in this case scrollViewDidEndDecelerating isn't being called, so we have to implement scrollViewDidScrollToTop to handle this case.
  • Nikhil Manapure
    Nikhil Manapure over 6 years
    This answer is best, and @JovanStankovic, you are very correct.