How to know that tableView started scrolling

Fabio Cenni picture Fabio Cenni · Aug 28, 2015 · Viewed 18.3k times · Source

I have a doubt: is there any way to intercept a tableView scrolling to add it an action? For example my prototype cell background is red, touching up inside a cell its background color begin blue and scrolling the tableView background color return red. Is it possible to do this?!

Thanks in advance.

Answer

redent84 picture redent84 · Aug 28, 2015

UITableView inherits from UIScrollView and UITableViewDelegate extends UIScrollViewDelegate.

Particularly you may be interested in scrollViewDidScroll method. So, in your UITableViewDelegate implementation, add the following method:

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    NSLog("Table view scroll detected at offset: %f", scrollView.contentOffset.y)
}