Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to be notified when a UITableView finishes scrolling?

I referenced this question: How to detect when a UIScrollView has finished scrolling

UITablewView is a subclass of UIScrollView, and my UITableView delegate does get the - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView message when I scroll the table by hand.

However, when I call - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated to scroll the table, I don't get the scrollViewDidEndDecelerating message. I am calling the scrollRowToIndexPath... method with animated:YES.

Is this a bug/API limitation (on iPhone SDK 3.1.3) or am I missing another way to do this?

like image 471
Chris W. Avatar asked Mar 01 '10 18:03

Chris W.


2 Answers

Just in case someone is still chasing this one, the Apple docs say the following under the scrollToRowAtIndexPath:atScrollPosition:animated: documentation:

"Invoking this method does not cause the delegate to receive a scrollViewDidScroll: message, as is normal for programmatically-invoked user interface operations."

like image 70
oldbeamer Avatar answered Oct 22 '22 18:10

oldbeamer


I had the same problem. But I solved it by doing this after programmatically scrolling to the specified row:

NSTimer *t = [NSTimer scheduledTimerWithTimeInterval: 0.6
                                              target: self
                                            selector:@selector(doneScrolling)
                                            userInfo: nil repeats:NO];

In my case, I just wanted to highlight the row after it was scrolled to.

OR

If you want the code executed more immediatly and don't want to wait for .6 seconds, you might be able to loop to keep checking whether the row that you've scrolled to is visible yet. Use the visibleCells property on the UITableView. When it's visible, then you know it's done scrolling and you can execute your code.

like image 42
Trevor Avatar answered Oct 22 '22 19:10

Trevor