A infinite/endless paging UIScrollView

, Johannes M. Schleicher

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.

Johannes M. Schleicher
code

comments powered by Disqus

 

Recent Posts

 

Kinect on MacOS X with Homebrew

How to get libfreenect running with homebrew on MacOS X 10.8

Updating sitemap file on Heroku

Updating the sitemap.xml on Heroku for your rails application by using the sitemap_generator gem and AWS S3/CloudFront.

Various ActiveResource Tips

Enabling Logging, Set different model name, Set HTTP headers, Set xml/json format

Show NSWindow below your NSStatusItem

Show your own window below your status bar application.