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?
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).
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.
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 :)
Best method I've found is to use the isTracking
property rather than isDragging
.
if tableView.isTracking && tableView.isDecelerating {
// Table was scrolled by user.
}
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With