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

How to Reload Entire app settings programatically in swift 2

我写了一个应用程序,我需要在默认设置更改时重新加载所有设置。

但我没有头绪。我尝试重新启动或重新加载第一个视图控制器,但它没有用。我的问题是在我从核心数据中获取并从中加载标签的所有视图控制器中,但我必须关闭应用程序并重新启动它才能看到更改。

知道如何完成这个吗?

您的核心问题是更改设置后重新加载数据。有很多方法可以达到这个目的。一种是使用 KVO 观察所有要更改的 UI 元素的设置。

还有另一种强制方法可以让您不需要重新启动应用程序。

因为您的所有数据都在 viewControllers 的 init 方法之后使用。不要先重新加载 viewController,而是更新应用程序的 rootViewController 并设置它。

更改设置后。

if let tabBarController = UIApplication.sharedApplication().keyWindow?.rootViewController as? UITabBarViewController {
  let naviController1 = UINavigationController(rootViewController: HomeViewController())
  let naviController2 = UINavigationController(rootViewController: AccountViewController())
  tabBarController.viewControllers = [naviController1, naviController2]
}

UIApplication.sharedApplication().keyWindow?.rootViewController = YOURTabBarController()