无法加载从标识符为“(null)”的包中的笔尖引用的图像

发布于 2024-12-23 04:01:27 字数 1077 浏览 4 评论 0原文

我有一个应用程序,使用户能够在运行时从应用程序切换语言,一切正常,但是当切换到另一种语言时,加载加载该语言的本地化 Xib,但此 Xib 内没有任何图像。下面是我用于的代码切换到另一种语言。

 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;

这是 Xcode 调试中发生的错误,

Could not load the "sahdow.png" image referenced from a nib in the bundle with identifier "(null)" 

我非常高兴帮助我解决这个问题,这花了我很多时间。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一曲爱恨情仇 2024-12-30 04:01:27

您加载笔尖的方式是错误的,它也会迫使您本地化图像“sahdow.png”。事实上,如果你本地化图像,你会看到错误消失 - 但我仍然会避免这条路径。

iOS 会自动处理其设置中的语言更改,并加载适当的本地化 xib(如果有)。 我建议您避免在代码中显式加载本地化的 xib,而是将其留给 iOS,通过以下方式实例化您的视图控制器:

HomeViewController *homeVC = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];

注意: 对于我的回答,我假设您的 nib 文件中故意引用了“sahdow.png”。如果不是这种情况,请在您的 nib 文件中查找此图像的引用并将其删除。

PS:我刚刚发现另一篇文章 其中提到了您用来加载本地化笔尖的解决方案,以及它所具有的副作用 - 例如要求所有相关图像也进行本地化。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文