I have a UISlider
with values from 0 to 1.
The problem is if I slide it to a value, then close the app and reopen the app, the UISlider will stay on the value set by the sliding. Basically it remembers the value that it was last on.
I've tried some code to set it so that it can always be on 0 when the ViewController appears but it doesn't work. I tried this code in viewDidLoad
:
mySlider.value = 0;
And I've also tried this:
[mySlider setValue:0]
But neither of them work.
How I can have the UISlider always on 0 when the app opens ?
Put your code ([mySlider setValue:0]
) in viewWillAppear
if you don't want to see the slider value change, in viewDidAppear
if you want to see it change.
viewDidLoad
is only called when you create the view, it's not called when you display it after it has been loaded (for example, exiting the app and comming back, comming back from a push/pop in the navigation of a UINavigationController
, etc.).
Note you can use this method : [mySlider setValue:0 Animated:YES];
if you want to see the animation.