问题
I'm very new to objective c (three weeks) and also in my 70s so not as quick as I used to be! Anyway, I'm doing okay with an app for IOS except for a problem with maintaining slider position and value when switching away from a view and back again. To clarify: I have 3 views, each with 4 sliders and I want to be able to return to any view with the sliders positions and values the same as they were left. I'm sure there's a way of doing this but I've searched all over to no avail so I hope someone here can help!
回答1:
Do you allocate an instance of a viewController every time you push it onto your navigation stack ? if so , create a property and allocate it only once and use the same object to push in onto your navigation stack. it should retain the position.
Another possible solution is to persist the current value of the slider in your viewController and set the slider value to the persisted value in viewWillAppear , which gets called every time the view comes on screen
回答2:
You could save the sliders values using something like NSUserDefaults. Look it up for more info.
来源:https://stackoverflow.com/questions/24170781/maintaining-slider-position-in-xcode-when-switching-views