Search code examples
iphoneiosios4nslocalizedstring

switching XIBs on the fly according to a specific localization


I use these methods

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"ar"] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize]; 

to force my app to change its localization during run time (when the user taps a button which simple calls these methods) and it works perfectly, however, these methods are not sufficient to switch the whole XIB to the new language (which is in my case, Arabic language), giving that I have one XIB named HomeViewController.xib that opens as a directory in XCode, a directory of two files: HomeViewController.xib (English) and HomeViewController.xib (Arabic) each file has its own layout according to language (for ex. Arabic xib has right to left controls layout ..), i've tried to call removeFromSuperView for every control on the current controller and then call addSubView for the controls, but nothing has changed, the app still displays the english XIB.

how can I let my app to change its XIB to the correct localized one at run time when that language button tapped.

p.s. when I change the whole simulator localization in system settings, the app works as expected, i.e. it displays the correct localized XIB.


Solution

  • some fellow developer almost solved the issue, please have a look at this sample app: https://rapidshare.com/files/3434929956/LangSwitch.zip it switches the whole XIB on the fly from Arabic to English and vice versa, what i'm stuck at right now is : I need this sample app to be tabbed, i.e. with a tab bar controller with two tabs, each tabs contains one view controller (you know, the usual way), anybody solves this problem I'd be sooo grateful to him/her ... waiting for your help guys ...