Archive for February 11th, 2009

11
Feb

UITableView dispatching

And today, we draw your attention to an interesting exploration of how to make your sectionized UITableView handling code less fragile by creating subclasses for each section handling.

I’ve developed a technique … allowing you to delegate the handling of each section in a table view to its own class. It is also easily configurable if you need to add or remove a section type from your controller later, and allows you to localize your changes so that you don’t have to remember to modify code in several places.

The basis of my technique is to create a main view controller for the table view, in this case calledNoteViewController, and separate section controllers for each section that inherit from anAbstractNoteSectionController class that I created. This class defines the interface for the section controllers and provides reasonable default behavior in case I don’t need specific behavior in my subclasses…

Using this technique, I was able to split up a hard to read and manage 700 line behemoth class into much more managable 80-200 line pieces and improve the readability and flexibilty of my code immensely. Hope you find this useful in your iPhone development.

Indeed. Give it a read the next time you start to find yourself buried under switch statements!