maintaining slider position in xcode when switching views

 ̄綄美尐妖づ 提交于 2019-12-08 13:39:39

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!