Chris W.
Chris W.

Reputation: 655

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?

Upvotes: 6

Views: 4057

Answers (3)

golu_kumar
golu_kumar

Reputation: 261

In case of scrolling programmatically you can use UIScrollViewDelegate methods in swift.

func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
  //your code to execute after scrolling.
}

in objective

-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
 //your code to execute after scrolling.
}

Upvotes: 0

oldbeamer
oldbeamer

Reputation: 1285

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

Upvotes: 6

Trevor
Trevor

Reputation: 4860

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.

Upvotes: 1

Related Questions