iphone - Saving application data state on exit -
I have an NSMutableArray with 24 strings.
I need to save this data if a user makes a call or leaves the application.
I see in many instances, but for some reason the best way to save data can not be determined.
The 24 strings correspond to 24 buttons and their state. When a button is clicked, it displays related array information for that button tag (0 - 23). What do I need to maintain, if 10 buttons and their data are clicked, what would be the best way to keep this data, so that it can be reloaded when the app starts?
I think I will need to store:
button tag, array value corresponding to buttons, button
(whether clicked and showing value or No)
I will store the application when I exit this data and then when the app is restarted, I will decide whether this stored data exists, if so, the array To determine the key and test the states of the button Whether it has been shown already and if so, then set it accordingly. Then when this file was loaded, I will destroy the stored data. In this way, if a user resigns, then in the next beginning, it will start a new game.
I have looked at several instances, where they store the data in a DAT file, but there is a problem applying this problem .... And thinking that this is also the best way.
Any help or idea is appreciated on this.
Geo ...
You can save data to a plist in the document directory Are there. If the data is there, then load it, and if not, it will suggest a clean run.
To load the data:
NSArray * path = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); NSString * Document = [Path ObjectAddIndex: 0]; NSString * filePath = [document string: bubbing money company: @ "buttonstate.lilist"]; NSMutableDictionary * buttonState = [[NSMutableDictionary alloc] initWithContentsOfFile: filePath];
To save the data:
[buttonState writeToFile: filePath atomically: Yes];
Comments
Post a Comment