views:

139

answers:

2

I have a UITableViewController which is starting to get a bit crazy with all the switch statements for each UITableView delegate.

Does anyone have any suggestions or examples of more of a data driven implementation for a UITableViewController? I'm thinking some type of data structure which would hold references of where to go to get cells for certain section/rows, where to get the section names, etc.

I think the More iPhone Development book describes something like this, just wanted to poll the community and see if anyone had some lessons learned on their own implementation.

A: 

I don't think there is a standard one that is generally suitable for everyone, but it's not too hard to whip up your own to suit the needs of your application. Basically, you want an array/list of sections, and for each section, an array/list of items. For each item, you'll want to allow specification of an image, text, detail text, and some sort of action to be fired upon selection.

If you want to get fancy, you can specify background colors, fonts, and other such things for each section heading, section footer, and item.

If your list items don't all look the same, then your tableView:cellForIndex: implementation needs to be smart enough to use different reuse identifiers for different-looking items.

A nice thing about this approach is that you can often use the same view and same controller for many "screens".

Consider using Core Data and NSFetchedResultsController.

Kristopher Johnson
A: 

Core Data's NSFetchedResultsController will do most of the data work for you. It might be overkill if your model is simple or not persisted though.

St3fan