user1118019
user1118019

Reputation: 3959

infinite scroll in tableview using footer

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!!

Upvotes: 2

Views: 1463

Answers (2)

sergio
sergio

Reputation: 69027

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.

Upvotes: 1

fzwo
fzwo

Reputation: 9902

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.

Upvotes: 5

Related Questions