Storing Displaying high scores.

Discussion in 'iOS Programming' started by playboy16, Jun 23, 2009.

  1. playboy16 macrumors newbie

    Joined:
    Jun 23, 2009
    #1
    Hi,

    I am new to iphone development. I have got most of my app together except for the high scores screen. Anyone know of any sample code? I am not looking for anything crazy. Just a way to store a name with a score, retrieve all of the stored scores and display them in a table with 2 columns. Thought I would ask instead of spending 8 hours trying to invent something myself. I was initially thinking of using NSUserDefaults to store the data and synch 2 table views to display the 2 columns. Any input? thanks!
     
  2. BlackWolf macrumors regular

    Joined:
    Apr 9, 2009
    #2
    that's probably the way to go if you don't have a lot of data. NSUserDefaults and then you just read from NSUserDefaults and display it in a way that seems suited, like in a table or something ^^
     
  3. playboy16 thread starter macrumors newbie

    Joined:
    Jun 23, 2009
    #3
    Thanks. Will try that.

    Any idea how to display it in a table? I was wrong, I need 3 columns.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    In terms of the data backing the table, store it in an array and use the UITableViewDatasource methods to populate the table. In terms of UI, since you want 3 columns you will probably need to add your own custom views, which can be as simple as UILabels, to the contentView of each cell. Another approach is to subclass the UITableViewCell class and go from there.
     
  5. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    Store an array of dictionaries in the NSUserDefaults. Each dictionary represents one high score. Add to the dictionaries the properties of the high score: score, name, date whatever else you want (but the properties need to be standard NS classes like NSString, NSNumber).

    You can keep the last N high scores and sort them by date or score in your dictionary. You will probably need to make a mutable copy of your array and dictionaries when you want to modify them.
     
  6. playboy16 thread starter macrumors newbie

    Joined:
    Jun 23, 2009
    #6
    I think I can handle the storing the retrieving of the high scores. Does anyone have an example of subclassing the UITableView class to display mutiple columns?
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7

Share This Page