Displaying Data on the iPhone with Index UITableView

It is forgone conclusion that if you need to present a large amount of data with a UITableView then you should do so using an index and index sections.  As with most tutorials that I have read on this topic, the scenarios used got me 80% of the way.  In my humble opinion, the solutions where either over engineered or they didn't apply to my use case.  Hopefully this tutorial/sample project will bridge the gap.

The tutorial that I got the most from is: iPhone Development: Creating Native Contacts like screen.

One of the biggest hurdles that I had to over come, that was different from the contacts tutorial, was that I wasn't using a database and therefore didn't have a predefined sub-result set for each character.  I was having to do the opposite.  I had to iterate over my result set, array of states, grab the first letter from each item, check to see if there was already a dictionary key that existed for that letter and proceed accordingly.

Logic Flow
Iterate over states
Get the first letter of that particular state
Check to see if there is a key in the objectsForCharacter dictionary
   - YES: add the state string to the arrayOfNames array and then set the arrayOfNames to the objectsForCharacter dictionary for the appropriate key
  -  NO: remove all objects from the arrayOfNames array and add the firstLetter to the arrayOfCharacters.  Then proceed on to the above "YES" steps
Once all the states have been "proceed" then reload the table data

Final Model
Though it sounds some what complicated with all the arrays, dictionarys, etc. once you break it down to a visual model then the code is easier to comprehend.

[[objectsForCharacters objectForKey:@"A"] objectAtIndex:0]; // Alabama
[[objectsForCharacters objectForKey:@"A"] objectAtIndex:1]; // Alaska
[[objectsForCharacters objectForKey:@"A"] objectAtIndex:2]; // Arizona
[[objectsForCharacters objectForKey:@"A"] objectAtIndex:3]; // Arkansas

Download Example Project (comments/enhancements are welcomed)
IndexedTable.zip
9 responses
Really a nice tutorial!!
@Sneha Thank you.  If there are any enhancements that you would like to see to it then let me know.
This helped expedite some work I was doing, thank you!
Anytime Jim. If there are any improvements u would like to see let me know. 

Sent from my iPhone
Many a thanks for this wonderful info.
Very useful and effective tutorial and post
Hi there I was woundering if you will be fixing the error you get when I try to check your example code, this sounds exactly the the problems I have been having with indexed table views

this is the error I get
NoSuchKeyThe specified key does not exist.examples/IndexedTable.zip5CB0EB078ED753E8ls1pHdPIoTQUTU3hn3RolpVVNo/qj0lB/lVa0xNYw37imlYIqHiwPk7fX8SQBp9m

regards.

What iOS version are u using?  I'll take a look at this for u. 

Sent from my iPhone
@webznz I just realized that the blog post still pointed to an old version of the app. Try the version that is on github. The links in the blog post have been updated. If you still have problems then let me know.