I’m currently involved in a project where I need to load some photos from the web and I need a UITableview with some thumbnails and with Photo.app navigation.
Enter Three20. Three20 is a framework written by Joe Hewitt that abstracts much of the functionality of UITableViews, UITableViewCells, and networking away from the programmer. The way the components are abstracted is clearly MVC, but done in a more “web application” way. I believe Joe commented in his recent interview on the Mobile Orchard podcast.
When you download Three20, there is a nice sample app included with just about everything you can create. This provides a great overview of what is included within the framework.
The functionality of the UIKit classes has been abstracted to the point that you never really touch the usual delegate and datasource methods. You create view and controller objects through a completely different programmatic interface.
You can create tableviews and photo galleries very easily by just adding creating a data source array and the view classes basically take care of themselves. This was very cleanly done. For instance, to determine the type of cell that will appear in your table, you populate your datasource with a specific type of *Field object. A TTTextTableField produces a text cell, a TTSwitchTableField yields a cell with a switch, etc…
To create a Photo Browser View and/or a Photo Thumb View is slightly more difficult. You will need to define your own Photo Datasource class. In the example code, there is a mock photosource class setup that provides a good starting framework.
Unfortunately, the requirements for my current project didn’t allow me to use the Three20 classes as is. I had to dig a little deeper into the framework and modify it to suit my needs.
When you dive into the code, you quickly find all the Cocoa classes have not been merely subclassed, but have had there behaviors completely altered. I could use the basic, high-level classes, but I could not understand exactly how they worked behind the scenes. I needed to subclass the TTThumbViewController and I had to understand what I needed change to make it work for me.
To be frank, it is complicated. So complicated, I considered giving up subclassing it several times during my adventure. As I began to decipher the interconnections and roles of different objects, some design patterns began to fall out. An interesting note is Three20’s use of delegates. There are many delegates and controllers and controller delegates and datasource delegates, etc… This was one of the main reasons it was hard for me to fully comprehend the framework. I literally had to pull a notebook out and start drawing the connections between the classes.
After a few hours, I felt I had a decent understanding of the underpinnings of the relevant classes which I needed to alter. I began to make my construct my classes and finally accomplished my goal of customizing the thumbs view to the following:
I know, not very impressive on the surface. What I managed to do was add section support to the TTThumbsViewController. The stock class only supports a single section with no division between the rows of photos. Also, it only supports one photo source per view. I have changed it to allow a photo source per section (Even though it looks like one source, it’s actually 2 sources with the same data).
It’s not bug free yet, and [redacted] betas are a little picky. When I get a little more solid, I’ll see if I can get a fork going on GitHub and upload my additions there.
In the end, I think it was worth getting intimate with Three20 to get all of the networking and photo browsing goodness for free.
I encourage everyone to check out Three20. It works great for just about anything you want to do. If it was my decision, I would have just changed my design to accommodate the framework and save myself a weekend.
Let me know if any of you have used Three20 and what your experiences were.

6 Comments
That is a very useful set of tools.
@Johann Definitely. A lot of work has gone into making common tasks rather trivial.
We are looking into Three20. There are a number of excellent components (ie the tab bars), but also a huge amount of complexity to understand in order to do anything useful, as you say.
Just starting to get into using the Styles. Its great to be able to create glossy buttons etc with a few lines of code.
@Matt
Yeah. it is a tough decision. It depends where you want to spend your time and if you can live with Three20’s set of customizations available to you “off-the-shelf”. If so, then I don’t think it’s a terrible option.
I really didn’t want to implement a photo browser and thumb photo picker, hence my interest. If I hadn’t been required to change the appearance of the thumb photo picker, it would have been cake.
I was hesitant at first, but then I was just to invested to turn back. So now I know my way around and won’t be too worried about using it in the future.
How did you get the photo datasource to look at your local photos? I am trying to figure out how to point my datasource to images in my project. Any code or advice would be greatly appreciated! Thanks!
@josh
I actually never got it to work with local photos. If you go to the google group page however, there is a nice sample project where someone implemented a photosource. (Even though it still works over the network)
http://groups.google.com/group/three20/web
I would imagine you only need to give the photo table a file url as a string. There may be a setting in there to alert 320 that it is a local url as file urls are initialized with a different method than remote urls (see NSURL class docs). I know that 320 IS supposed to handle both local and remote data.
I would recommend posting this question on stackoverflow. If you haven’t already.
Hope this helps.
One Trackback
I found Three20 and my lost weekend…
You’ve been kicked (a good thing) – Trackback from iPhoneKicks.com – iPhone SDK links, community driven…