PDA

View Full Version : Storing Displaying high scores.




playboy16
Jun 23, 2009, 11:42 PM
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!



BlackWolf
Jun 24, 2009, 12:29 AM
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 ^^

playboy16
Jun 24, 2009, 12:58 AM
Thanks. Will try that.

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

dejo
Jun 24, 2009, 09:26 AM
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.

PhoneyDeveloper
Jun 24, 2009, 11:29 AM
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.

playboy16
Jun 24, 2009, 11:50 AM
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?

dejo
Jun 24, 2009, 12:04 PM
Does anyone have an example of subclassing the UITableView class to display mutiple columns?
http://icodeblog.com/2008/09/02/iphone-programming-tutorial-creating-a-todo-list-using-sqlite-part-2/