Select Page

Infinity is a very powerful concept, so maybe my post title shouldn’t include this term. Anyway, I tried to create something similar to a infinite or endless paging scroll view.

The idea is very simple:

  1. Create a view including a standard scroll view.
  2. Provide an interface to load views for each page on demand.
  3. Cache views for pages (specify the maximum amount of cached pages).
  4. If user scrolls the view load (and cache) the next and previous view.

You will find the source code of this component (I named it InfinitePagingView) and a example project at our github repository.

Using InfinitePagingView  is very straightforward. Just implement the InfinitePagingDataSource  protocol, create an instance of InfinitePagingView  and add it to your current view:

InfinitePagingView *infinitePagingView = [[InfinitePagingView alloc]
            initWithFrame:CGRectMake(0, 0, 320, 480)
            andDataSource:self];

[self.view addSubview:infinitePagingView];
[infinitePagingView release];

After that -(UIView*) infinitePagingView:(InfinitePagingView*)infinitePagingView viewForPageIndex:(int)index  gets called for each page and you can provide your custom view for the requested page.