Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if UITableView is being scrolled manually (by hand) or programmatically?

I am using a UITableView in my code and it would be nice to know if the user manually scrolled the UITableView or it was done programmatically. Is there a way to know that?

like image 345
Ahsan Avatar asked Jul 28 '11 18:07

Ahsan


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).


4 Answers

UITableView is a subclass of UIScrollView. so you can use this

if (!tableView.isDragging && !tableView.isDecelerating)
{
   // the table is *not* being scrolled
}

this works. i use it in one of my apps.

like image 155
roocell Avatar answered Oct 18 '22 12:10

roocell


You can implement following method of UIScrollViewDelegate, to know about the scrolling of your table view:

- (void)scrollViewWillBeginDragging:(UIScrollView *)activeScrollView

Don't forget to put this on too...

@interface YourViewController : UIViewController <UIScrollViewDelegate>

Hope it helps, cheers :)

like image 35
Waleed Mahmood Avatar answered Oct 18 '22 14:10

Waleed Mahmood


Best method I've found is to use the isTracking property rather than isDragging.

if tableView.isTracking && tableView.isDecelerating {
    // Table was scrolled by user.
}
like image 26
Beau Nouvelle Avatar answered Oct 18 '22 12:10

Beau Nouvelle


Use this to detect both fast and slow scrolling caused by user interaction:

if tableView.isDragging, tableView.isDecelerating || tableView.isTracking {
    // Table view is scrolled by user, not by code
}
like image 29
Ely Avatar answered Oct 18 '22 14:10

Ely