kishan
kishan

Reputation: 203

Reload storyboard to change language

I am implementing multiple language support in a app. Can any one say how to reload storyboard to change localised text without restart of app?

Upvotes: 2

Views: 2610

Answers (1)

Umair Ali
Umair Ali

Reputation: 836

To reload storyboard you need to set RootViewController on changing language. You can use bellow line of code to set RootViewController:

  let firstVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FirstViewController")
  let rootviewcontroller: UIWindow = ((UIApplication.shared.delegate?.window)!)!
  rootviewcontroller.rootViewController = firstVC

If you want to embed navigation controller in firstVC you should use following line of code:

  let firstVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FirstViewController")
  let nav = UINavigationController(rootViewController: firstVC)
  let rootviewcontroller: UIWindow = ((UIApplication.shared.delegate?.window)!)!
  rootviewcontroller.rootViewController = nav

Upvotes: 2

Related Questions