Need help with table view and sections

Discussion in 'iOS Programming' started by HawaiiMacAddict, Jun 11, 2009.

  1. HawaiiMacAddict macrumors 6502a

    Joined:
    Dec 28, 2006
    Location:
    On one of my Macs of course
    #1
    Aloha everyone,

    I am currently working on an app that uses a SQLite3 database to populate a table view with terms. Once the user clicks on one of the terms, another view pops up with the definition. What I can't figure out how to do yet is make section headers on that first table view (the one with the terms). I can do it quite easily with a plist, but I'm using a database pull instead. Can anyone point me in the right direction to understand how I can accomplish this?

    Thanks in advance for all responses
     
  2. HawaiiMacAddict thread starter macrumors 6502a

    Joined:
    Dec 28, 2006
    Location:
    On one of my Macs of course
    #2
    Aloha everyone,

    After thinking about this one for a bit, I added a new column (field) to my SQLite table (basically re-creating it, but I only have five items in it anyway :D) named 'key' containing the first letter of the term for that entry. I want to show the index down the right-hand side of the tableview, but only show the letters for which I have associated terms beginning with them (the letter in the index). I was thinking about using a for loop to go through that field, counting up the terms beginning with each letter and returning the count as the value for numberOfRowsInSection: method.

    Does that sound as if I'm on the right track or is there a simpler way to do this?

    Thanks in advance for your responses
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    That's one way to do it. Another way, since your data is in SQLite, is to use a SQL query involving GROUP BY and COUNT.
     
  4. HawaiiMacAddict thread starter macrumors 6502a

    Joined:
    Dec 28, 2006
    Location:
    On one of my Macs of course
    #4
    Aloha dejo,

    Thanks for your response. I was hoping that an easier way could be had, and that someone with more experience with SQL than I could give me a nudge in the right direction.

    Here's another question. What with iPhone OS 3.0 having the Core Data API built in, how long would you suggest developers such as myself continue to use SQL?

    Thanks again in advance for your response
     

Share This Page