I have a simple app, which contains two XIBs, each one is localized (for two languages en and ar for arabic) using XCode Add Localization feature in File Inspector pane..
I have placed two buttons in the root view controller xib
to switch the app language and switch to the other localized XIB, the app works perfectly, except for one small issue: the Arabic XIB contains an image inside an imageView
, and also the english XIB contains an image inside an imageView
,
1) when I switch the language from English to Arabic, the Arabic XIB comes in place but without the image
2) and vice versa when I switch from Arabic To English
3) and even at app launch it does not display the image: XCode produces this error in these 3 cases in Console without crashing the app:
2011-12-27 12:48:30.412 LangSwitch[4903:f803] Could not load the "image1.png" image referenced from a nib in the bundle with identifier "(null)"
the didFinishLaunchingWithOptions
method code is:
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(lang:) name:@"Lang" object:nil];
// Override point for customization after application launch.
// Set the navigation controller as the window's root view controller and display.
NSString* str = [[[NSUserDefaults standardUserDefaults]valueForKey:@"AppleLanguages"] objectAtIndex:0];
NSBundle* bnd = [NSBundle bundleWithPath:[[NSBundle mainBundle]pathForResource:str ofType:@"lproj"]];
RootViewController* cont = [[RootViewController alloc]initWithNibName:@"RootViewController" bundle:bnd];
self.window.rootViewController = cont;
[self.window makeKeyAndVisible];
and the lang
selector code is:
- (void)lang:(NSNotification*)sender{
//NSLog(@"%@",[sender object]);
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:[sender object],nil] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults]synchronize];
NSString* str = [[[NSUserDefaults standardUserDefaults]valueForKey:@"AppleLanguages"] objectAtIndex:0];
NSBundle* bnd = [NSBundle bundleWithPath:[[NSBundle mainBundle]pathForResource:str ofType:@"lproj"]];
RootViewController* cont = [[RootViewController alloc]initWithNibName:@"RootViewController" bundle:bnd];
self.window.rootViewController = cont;
[self.window makeKeyAndVisible];
}
and here is the sample app that contains what I'm describing above. if you guys could help solving this issue i'd be so grateful to you.
thank you so much in advance...