Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

playboy16

macrumors newbie
Original poster
Jun 23, 2009
13
0
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!
 
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 ^^
 
Thanks. Will try that.

Any idea how to display it in a table? I was wrong, I need 3 columns.
 
Any idea how to display it in a table? I was wrong, I need 3 columns.
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.
 
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.
 
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.