I have a date picker thats is set to time. The time from the picker is shown in a textfield. I need to save the data on app exit to the NSUserDefalult and later load the time from NSUserDefalult. Also how could I save the datePickers location on the same time I used it last time.
Asked
Active
Viewed 282 times
0
-
Sorry for the duplicate, I had searched earlier and couldnt find anything to do with this. I guess I wasnt searching the right keywords. – Aug 05 '13 at 20:36
1 Answers
2
To save the data in NSUserDefaults
// create a standardUserDefaults variable
NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults];
// saving an NSString
[standardUserDefaults setObject:@"YOUR DATE VALUE TO BE SAVED" forKey:@"date"];
// synchronize the settings
[standardUserDefaults synchronize];
To retrieve the data from NSUserDefaults
// create a standardUserDefaults variable
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
// Checking if the Data exists.
if([standardUserDefaults objectForKey:@"date"] != nil) {
// getting an NSString object
NSString *myDate = [standardUserDefaults stringForKey:@"date"];
}
Now set the date back to UITextField
textField.text = myDate;

icodebuster
- 8,890
- 7
- 62
- 65
-
Sorry but im really new to programming and I got no idea what to do with this. where do I put the two codes? And how do I set the sate back to the textfield? – i_duhh_bomb Aug 05 '13 at 17:50
-