0

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.

  • 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 Answers1

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