Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get scrollViewDidScrollToTop to work in a UITableView?

I think the title explains it all. I want to be notified when a user scrolls to the top of a tableview.

I've tried the following with no luck and even added a UIScrollViewDelegate to the .h file.

- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView{
    NSLog(@"ScrolledToTop");
}

Thanks!

Edit: I can get it to call if I press the status bar. But not if I scroll to the top. Weird... could it have something to do with the tableview bouncing when it reaches the top?

like image 325
Jonah Avatar asked Jan 21 '10 23:01

Jonah


2 Answers

What happens if you try this?

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView.contentOffset.y == 0)
        NSLog(@"At the top");
}
like image 114
Mike McMaster Avatar answered Sep 22 '22 21:09

Mike McMaster


- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

if (indexPath.row == 0 && indexPath.section == 0 ) {
    NSLog(@"Showing top cell");

}

Is that close enough?

like image 27
justin Avatar answered Sep 23 '22 21:09

justin