Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know that tableView started scrolling

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.

like image 755
Fabio Cenni Avatar asked Aug 28 '15 10:08

Fabio Cenni


People also ask

How can I tell if a tableView is scrolling in Swift?

Since a scrollView has a panGesture we can check the velocity of that gesture. If the tableView was programmatically scrolled the velocity in both x and y directions is 0.0. By checking this velocity we can determine if the user scrolled the tableView because the panGesture has a velocity. Save this answer.

Is tableView scrollable?

If the number or rows from the datasource is more than what can fit onscreen, the table will scroll. If you want to programmatically scroll the table, you can use the offset property on UIScrollView or one of the methods on UITableView to do that. D.C. Save this answer.

How do I make a tableView not scrollable?

You need to set the UITableView scroll to false , tableview. scrollEnabled = false; tableview.

What is UITableView in Swift?

A view that presents data using rows in a single column.


1 Answers

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)
}
like image 70
redent84 Avatar answered Oct 14 '22 07:10

redent84