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!
As Dave Batton said, NSUserDefaults is for defaults on fresh launches of the app. If I understand your question correctly, it appears to me that you are overwriting your default value in firstSliderValueChange. That is why this happens:
Either store your defaults and in-app values separately or pass them between views.
EDIT: The code mentioned in your comment below doesn't pass values. It persists values.
Problem: Say you originally have set a slider value default of 0. When you run the app for the first time, you see the slider at 0. Now you move the slider to, say, 5. Then this method is called:
Now the default value is no longer 0. It is 5. And that persists between app launches, since you are using NSUserDefaults.
Solution: Save the dynamic slider value some place else - not in NSUserDefaults. Since you have multiple view controllers, one way is this:
And:
Now, whenever you switch back to your first view controller's view, simply access this property, and update the slider accordingly. Note - I am sure there are many other ways of doing this!