The "current value" default I have set in interface builder for my sliders seems to be bypassed completely, and when I run the app, the sliders start from where I last had them set the last time I ran the app.
I would like the sliders to start from their default value AND recall the position they were last in, before switching to a different view.
Here is the code that allows the slider values to be saved:
viewController.m
- (void)viewWillAppear:(BOOL)animated{
[_firstSlider setValue:[[NSUserDefaults standardUserDefaults] floatForKey:@"firstSliderValue"]];
}
- (IBAction)firstSliderValueChange:(id)sender {
[[NSUserDefaults standardUserDefaults] setFloat:[_firstSlider value] forKey:@"firstSliderValue"];
}
Thank You!
Don't use NSUserDefaults to store the value between views. That's not what it's for. Just pass the slider value from one view to another. You may need to do this in
-prepareForSegue:sender:.Use NSUserDefaults when you want to save and restore a value between fresh launches of the app.
Notice that I'm setting a property on the destination view controller, not setting the slider value directly.
The destination view controller's view probably isn't loaded at this point, so the slider property is nil. Set this other property instead, and then when the view gets loaded (
-viewDidLoad) you can update the slider with that value.