2

I am trying to support infinite scroll in tableview. I know tableview lets scroll infinitely, but my case is different.

Initially, I will load 30 items in my tableview as the user scrolls down close to 30th element, I will make a http request to get next 30 items so its not like I am loading 60 items at once.

My way about going to do this is when my table is initally filled with 30 items, once the footerview is seen, then I will request the next 30 items.

My question is how to detect footerview is seen? Is there something like 'will appear' for just footerview?

Let me know if there is other better way of completing my scenario above

Thanks!!

Darren
  • 68,902
  • 24
  • 138
  • 144
user1118019
  • 3,819
  • 8
  • 40
  • 46

2 Answers2

5

A UITableView is a subclass of UIScrollView, and UITableViewDelegate conforms to UIScrollViewDelegate.

So you can set yourself as the tableViewDelegate and implement scrollViewDidScroll:. You can then either check the scrollView.contentOffset yourself, or call [myTableView visibleCells]. I am sure there are various other methods as well.

fzwo
  • 9,842
  • 3
  • 37
  • 57
1

The behavior you are trying to implement is known as pull-to-refresh.

There are several implementation of it already available, e.g.:

  1. https://github.com/leah/PullToRefresh

  2. https://github.com/enormego/EGOTableViewPullRefresh

Give it a try, or read the code the learn the details. If you are curious, the way the trick is done is by implementing the delegate methods for the scroll view and checking the value of scrollView.contentOffset.y.

sergio
  • 68,819
  • 11
  • 102
  • 123
  • 2
    If I understood him correctly, he wants to implement the exact opposite of pull-to-refresh. Though technically they're similar, of course. – fzwo May 03 '12 at 17:47
  • @fzwo: Well, you are right, but that is just a matter of changing the value for an offset in the code (y>something instead of y – sergio May 03 '12 at 17:49