I am currently creating a TableView application using sqlite and thus far, it works as intended. The first view is a listing of all states in the United States and returns them in alphabetical order in one section called “States”. My question is…How do I create an alphabetical sectioned list for this data? In other words, create a section named “A” that contains states Alabama, Alaska, Arizona, Arkansas. A section named “C” that would contain California, Colorado, Connecticut. It would basically comb the results, looking for the first letter in each state and if there is a match, place that state in the appropriate section.
I have come across some articles that describes how to do this but not relative to sqlite. Any help would be greatly appreciated!!
Thank you in advance!
One approach could be to feed a structure that is an array of array. Each section of the array will contain an array of States that match the same first letter of states. Work on this structure then to implement the datasource and delegate methods.
As it happen to me to do something very similar, here is a code snippet to feed the structure (self.browserContents). I hope it will help:
Note:
BrowserContents is a class that should contain the list of all states, the number of categories and id of the category it should belong to (e.g: A->1, B->2 etc… supposed you have states that start with A and B). Last check the book Professional iPhone and iPad Database Application Programming. This has been a great ressource to understand database programming in iOS.