[英]How to Reload Entire app settings programatically in swift 2
I wrote an app which I need to reload all settings when default settings has changed. 我写了一个应用程序,当默认设置更改时,我需要重新加载所有设置。
But I don't have a clue. 但是我没有头绪。 I tried relaunching or reloading first view controller but it wasn't working.
我尝试重新启动或重新加载第一个视图控制器,但是它不起作用。 my problem is in all view controllers I fetch from core data and load labels from it but I have to close the app and relaunch it to see the changes.
我的问题是我从核心数据中获取所有视图控制器并从中加载标签,但是我必须关闭应用程序并重新启动以查看更改。
any idea how to accomplish this ? 任何想法如何做到这一点?
Your core problem is reloading data after changing settings. 您的核心问题是更改设置后重新加载数据。 There are many ways achieving this purpose.
有很多方法可以达到这个目的。 One is using KVO to observe settings for all the UI elements you want to change.
一种是使用KVO观察要更改的所有UI元素的设置。
There is another force way to make you don't need relaunch the app. 还有另一种强制方式,使您不需要重新启动应用程序。
Because all your data used after the viewControllers' init
method. 因为您的所有数据都在viewControllers的
init
方法之后使用。 Instead of reloading first viewController, renew your application's rootViewController
and set it. 无需重新加载第一个viewController,而是更新应用程序的
rootViewController
并进行设置。
After changing your settings. 更改设置后。
if let tabBarController = UIApplication.sharedApplication().keyWindow?.rootViewController as? UITabBarViewController {
let naviController1 = UINavigationController(rootViewController: HomeViewController())
let naviController2 = UINavigationController(rootViewController: AccountViewController())
tabBarController.viewControllers = [naviController1, naviController2]
}
OR 要么
UIApplication.sharedApplication().keyWindow?.rootViewController = YOURTabBarController()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.