Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check when UITableView is done scrolling

Tags:

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?

like image 367
sankaet Avatar asked May 13 '13 12:05

sankaet


People also ask

Is UITableView scrollable?

UITableView is a subclass of UIScrollView that allows users to scroll the table vertically (the closely-related UICollectionView class allows for horizontal scrolling and complex two-dimensional layouts).

Can UITableView scroll horizontal?

You can add a UITableView to a UIScrollView and have it scroll horizontally.


1 Answers

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.

like image 129
shanegao Avatar answered Sep 27 '22 22:09

shanegao