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.
UITableView scrolls back because it's content size is equal to it's frame (or near to it). If you want to scroll it without returning you need add more cells: table view content size will be large then it's frame.
You don't need to intercept the event methods. Check the docs for the UIScrollViewDelegate
protocol, and implement the -scrollViewDidScroll:
or -scrollViewWillBeginDragging:
methods as appropriate to your situation.
I would like to add the following:
If you are working with a UITableView
it is likely that you are already implementing the UITableViewDelegate
to fill the table with data.
The protocol UITableViewDelegate conforms to UIScrollViewDelegate, so all you need to do is to implement the methods -scrollViewWillBeginDragging
and -scrollViewDidScroll
directly in your UITableViewDelegate implementation and they will be called automatically if the implementation class is set as delegate to your UITableView.
If you also want to intercept clicks in your table and not only dragging and scrolling, you can extend and implement your own UITableViewCell and use the touchesBegan: methods in there. By combining these two methods you should be able to do most of the things you need when the user interacts with the UITableView.
It was my mistake, I tried to call the method before reloading the tableview. The following code helped me solve this issue.
[mytableview reloadData];
[mytableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:btn.tag-1] atScrollPosition:UITableViewScrollPositionTop animated:YES];
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