The iOS framework that grows only as fast as its documentation
<NIPhotoAlbumScrollViewDataSource> Protocol Reference

Overview

The photo album scroll data source.

This data source emphasizes speed and memory efficiency by requesting images only when they're needed and encouraging immediate responses from the data source implementation.

See Also
NIPhotoAlbumScrollView
Inheritance diagram for <NIPhotoAlbumScrollViewDataSource>:
<NIPagingScrollViewDataSource>

Tasks

[NIPhotoAlbumScrollViewDataSource] Fetching Required Album Information
(UIImage *) - photoAlbumScrollView:photoAtIndex:photoSize:isLoading:originalPhotoDimensions:
 
[NIPhotoAlbumScrollViewDataSource] Optimizing Data Retrieval
(void) - photoAlbumScrollView:stopLoadingPhotoAtIndex:
 
[NIPagingScrollViewDataSource] Fetching Required Album Information
(NSInteger) - numberOfPagesInPagingScrollView:
 
(UIView
< NIPagingScrollViewPage > *) 
- pagingScrollView:pageViewForIndex:
 

Method Documentation

photoAlbumScrollView:photoAtIndex:photoSize:isLoading:originalPhotoDimensions:

Fetches the highest-quality image available for the photo at the given index.

- (UIImage*)photoAlbumScrollView:(NIPhotoAlbumScrollView *)photoAlbumScrollView photoAtIndex:(NSInteger)photoIndex photoSize:(NIPhotoScrollViewPhotoSize *)photoSize isLoading:(BOOL *)isLoading originalPhotoDimensions:(CGSize *)originalPhotoDimensions;
Discussion

Your goal should be to make this implementation return as fast as possible. Avoid hitting the disk or blocking on a network request. Aim to load images asynchronously.

If you already have the highest-quality image in memory (like in an NIImageMemoryCache), then you can simply return the image and set photoSize to be NIPhotoScrollViewPhotoSizeOriginal.

If the highest-quality image is not available when this method is called then you should spin off an asynchronous operation to load the image and set isLoading to YES.

If you have a thumbnail in memory but not the full-size image yet, then you should return the thumbnail, set isLoading to YES, and set photoSize to NIPhotoScrollViewPhotoSizeThumbnail.

Once the high-quality image finishes loading, call didLoadPhoto:atIndex:photoSize: with the image.

This method will be called to prefetch the next and previous photos in the scroll view. The currently displayed photo will always be requested first.

Attention
The photo scroll view does not hold onto the UIImages for very long at all. It is up to the controller to decide on an adequate caching policy to ensure that images are kept in memory through the life of the photo album. In your implementation of the data source you should prioritize thumbnails being kept in memory over full-size images. When a memory warning is received, the original photos should be relinquished from memory first.

photoAlbumScrollView:stopLoadingPhotoAtIndex:

Called when you should cancel any asynchronous loading requests for the given photo.

- (void)photoAlbumScrollView:(NIPhotoAlbumScrollView *)photoAlbumScrollView stopLoadingPhotoAtIndex:(NSInteger)photoIndex;
Discussion

When a photo is not immediately visible this method is called to allow the data source to minimize the number of active asynchronous operations in place.

This method is optional, though recommended because it focuses the device's processing power on the most immediately accessible photos.

numberOfPagesInPagingScrollView:

Fetches the total number of pages in the scroll view.

- (NSInteger)numberOfPagesInPagingScrollView:(NIPagingScrollView *)pagingScrollView;
Discussion

The value returned in this method will be cached by the scroll view until reloadData is called again.

pagingScrollView:pageViewForIndex:

Fetches a page that will be displayed at the given page index.

- (UIView<NIPagingScrollViewPage>*)pagingScrollView:(NIPagingScrollView *)pagingScrollView pageViewForIndex:(NSInteger)pageIndex;
Discussion

You should always try to reuse pages by calling dequeueReusablePageWithIdentifier: on the paging scroll view before allocating a new page.