Update: ELCImagePickerController

    March 3rd, 2011 Posted by: - posted under:Articles » Featured

    I recently spent some time with . For those of you who’ve worked with UIImagePickerController, you might have noticed one of its major drawbacks: you can only select one photo at a time. ELCImagePickerController solves this issue by cloning the UI of UIImagePickerController, but with the added bonus of allowing you to select multiple assets. Collin Ruffenach (), who authored the the first version of the picker, has done an awesome job of making ELCImagePickerController look, feel, and behave like a native image picker. For this post I’m going to go through some recent improvements I made to ELCImagePickerController and pass along some lessons learned from working with the AssetsLibrary Framework.

    This is my first foray into the AssetsLibrary Framework which was introduced with iOS 4.0. If you’re not already familiar with the framework, I highly suggest checking out both of these posts:

    Asset Libraries and Blocks in iOS 4

    Cloning UIImagePickerController using the Assets Library Framework

    These should give you a solid picture of how to work with ALAssetLibrary, ALAssetGroup, and ALAsset.

    One of the obvious changes I’ve made to the project is a reorganization of the code. Classes are broken out for clarity as you can see here:

    Old Tree:

    New Tree:

    I’ve also renamed several classes to avoid confusion w/ Apple’s and ELC’s respective classes.

    On major change to the project is how you present the new ELCImagePickerController. This is mainly due to an issue we uncovered with a redundant call to [super init] which was causing a substantial memory leak. Here’s the new way of showing the image picker:

    ELCAlbumPickerController *albumController = [[ELCAlbumPickerController alloc] initWithNibName:@"ELCAlbumPickerController" bundle:[NSBundle mainBundle]];ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initWithRootViewController:albumController];
    [albumController setParent:elcPicker];
    [elcPicker setDelegate:self];
    ELCImagePickerDemoAppDelegate *app = (ELCImagePickerDemoAppDelegate *)[[UIApplication sharedApplication] delegate];
    [app.viewController presentModalViewController:elcPicker animated:YES];
    [elcPicker release];
    [albumController release];

    One interesting optimization I was able to make was on the loading of large albums which was previously taking several seconds. Since ALAssetGroup uses a block to enumerate assets, I just fire off a reloadTable call after a short delay:

    // Show partial list while full list loads
    [self.tableView performSelector:@selector(reloadData) withObject:nil afterDelay:.5];

    Then when the block is finished enumerating, it’ll call reloadTable as well. On an album with roughly 1500 photos, it was pretty tough to reach the bottom of the tableview before the block finished enumerating. So this is a pretty decent solution to the issue. Originally, I experimented with lazy loading the assets as the user scrolled through the table, but ultimately wasn’t able to get the performance I wanted out of it.

    This release of ELCImagePickerController should perform faster, and with a smaller memory footprint than before. I hope you enjoy it.

    You can follow me on twitter or get in touch with us at

    ps. for an extra bonus, check out [ELCAsset toggleSelection];