Reputation: 812
I have an application that enabled that user to switch language at run-time from app,every thing is OK but when switch to another language load Load localized Xib for this language but without any images inside this Xib.below my code that is used to switch to anther language.
NSString* str = [[[NSUserDefaults standardUserDefaults]valueForKey:@"AppleLanguages"] objectAtIndex:0];
NSBundle* bnd = [NSBundle bundleWithPath:[[NSBundle mainBundle]pathForResource:str ofType:@"lproj" ]];
HomeViewController *homeVC = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:bnd];
UINavigationController *localNavigationController = [[UINavigationController alloc] initWithRootViewController:homeVC];
localNavigationController.viewControllers = [NSMutableArray arrayWithObject:homeVC];
localNavigationController.navigationBarHidden = YES;
NSMutableArray *navs = [NSMutableArray arrayWithObject: localNavigationController];
tabBarController.viewControllers = navs;
self.window.rootViewController = tabBarController;
and here is the error occur in Xcode debug
Could not load the "sahdow.png" image referenced from a nib in the bundle with identifier "(null)"
I am very please to help me to solve this problem it takes from me many hours.
Upvotes: 3
Views: 2673
Reputation: 2027
The way you're loading your nib is wrong, and it will force you to have the image "sahdow.png" localized too. In fact, if you localize the image, you will see the error go away - but still I would avoid this path.
iOS automatically handles language changes in its settings and loads the appropriate localized xibs if you have them. I recommend that you avoid explicitely loading localized xibs in your code, and leave that to iOS instead, by instantiating your view controller in the following way:
HomeViewController *homeVC = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
Note: For my answer, I'm assuming that "sahdow.png" is somehow referenced in your nib file on purpose. If this is not the case, please look for references of this image in your nib file and remove them.
PS: I've just found another post in which the solution you're using to load the localized nib is mentioned, and the side effects it has - such as requiring all related images to be localized as well.
Upvotes: 2