我有使用两种语言的故事板(Ar / En)的应用程序如何从阿拉伯语故事板切换到英语故事板,而无需更改语言iPhone设置(在运行时)。
当用户手动更改语言时,我使用:
+ (void)setDefaultLocalizationLanguage:(NSString *)language{
[UserPreferences setDefaultLanguage:language];
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:language, nil] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
在AppDelegate中,我添加了方法switchTolanguage:
-(void)switchTolanguage:(NSString *)lang{
NSBundle *bnd = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:lang ofType:@"lproj" ]];
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:bnd];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
self.window.rootViewController = initViewController;
}
我在ViewController中执行最后一个方法:
AppDelegate *appdelagate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appdelagate switchTolanguage:[UserPreferences defaultLanguage]];
但是我在这个日志中有相同的故事板本地化:
Could not load the "4_icon_4.png" image referenced from a nib in the bundle with identifier "(null)"
Could not load the "1_logo.png" image referenced from a nib in the bundle with identifier "(null)"
Could not load the "1_bacground_img.png" image referenced from a nib in the bundle with identifier "(null)"
但是当我杀死应用程序并打开它时,我就有了很好的故事板。