NSUserDefault 和开关 [英] NSUserDefault and Switches

查看:90
本文介绍了NSUserDefault 和开关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 NSUserDefaults 来保存开关的开/关,到目前为止还不错.它会记住下次会话的开关位置.

I use NSUserDefaults to save a switch on/off and so far it is good. It remembers the switch position in next session.

现在我不明白的事情.我在另一个视图中使用相同的开关(具有相同的名称),假设是从第一个视图推入的翻转视图.如果我在第一个视图中更改开关,它会在翻转视图中自动更改.但反过来说,如果我在翻转视图中更改它,当我返回时,它不会在第一个视图中更改.仅当我重新启动应用程序时,第一个视图也会更改.

Now to the thing which I do not understand. I use the same switch (with the same name)in another view, let´s say a flip view which is pushed in from the first view. If I change the switch in the first view it is automatically changed in the flip view. But the other way round, if I change it in the flip view it is not changed in the first view when I go back. Only if I restart the application the first view is also changed.

如何同时解决这个问题?或者无需重新启动即可刷新第一个视图.

How can I solve this to be changed at the same time? Or kind of refresh the first view without need to restart.

推荐答案

您的第一个视图不会刷新,因为它不会再次初始化.如果您使用 ViewControllers,您可以更新 viewWillAppear 中的开关(如果 isViewLoaded).

Your first view is not refreshed, as it is not initialized again. If you using ViewControllers you could update your switch in viewWillAppear (if isViewLoaded).

这篇关于NSUserDefault 和开关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆