简体   繁体   English

如何在Swift 2中以编程方式重新加载整个应用程序设置

[英]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.

相关问题 如何以编程方式使用 swift 用 UIView 覆盖整个屏幕 - how to cover the entire screen with a UIView using swift programatically 是否可以以编程方式打开设置应用程序? (不是设置应用中的应用设置) - Is it possible to programatically open the settings app? (not the app settings within the settings app) 如何在Swift 2中刷新或重新加载应用程序数据 - How to refresh or reload app data in swift 2 以编程方式快速重新加载应用程序 - Reload the app programmatically in swift Swift iOS 9应用不在设置中 - swift ios 9 app not in Settings 以编程方式导航到手机上的应用推送通知设置 - Programatically navigate to push notification settings of app on Phone 当应用程序来自后台时,IOS Swift 如何重新加载视图控制器? - IOS Swift how reload viewcontroller when app come from background? 如何在整个应用程序上按回车键时快速隐藏键盘? - How to hide keyboard in swift on pressing return key on entire app? 如何从应用程序内部或外部MDM以编程方式更改屏幕时间和隐私限制设置? - How to change Screen Time and Privacy restrictions settings programatically from inside an app or from an external MDM? 如何从 iOS Swift 5 中的应用设置启用推送通知? - How to enable push notification from app settings in iOS Swift 5?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM