无法在 iPhone 设备上加载捆绑包中的笔尖
我正在尝试测试我在 iPhone 上开发的应用程序。为此,我将 Xcode 上的目标从 Simulator 更改为 Device。应用程序已正确上传到设备并且可以运行。显示了主视图,但如果我尝试打开辅助视图,应用程序就会崩溃。
在iPhone日志上(我安装了iPhone配置实用程序来查看控制台[是从iPhone查看日志的唯一方法?])我可以看到此错误:
Could not load NIB in bundle
但是,在模拟器上它工作正常。怎么了?有什么想法吗?
I'm trying to test an app I'm developing on my iPhone. To do that I changed the target from Simulator to Device on Xcode. The application is correctly uploaded to the device and it works. The main view is shown but if I try to open a secondary view, the application crashes.
On the iPhone log (I installed the iPhone configuration utility to see the console [is the only way to see the log from iPhone?]) I can see this error:
Could not load NIB in bundle
But, on the simulator it works fine. What's wrong? Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(16)
我遇到了同样的问题,并像这样修复了它:
I had the same problem and fixed it like so:
我发现有时设备区分大小写,而模拟器则不区分大小写。
你的 xib 文件名是什么?
或者
尝试从模拟器中卸载应用程序并再次安装 - 模拟器可能有一个以前运行应用程序时留下的旧文件 - 您在开发过程中是否重命名/移动了 xib?
I've found that sometimes the device is case sensitive and the simulator is not.
What's the filename of your xib?
or
Try uninstalling the app from the simulator and installing it again - the simulator might have an old file left over from a previous run of the app - have you renamed / moved the xib at all during development?
我遇到了类似的问题,并且遇到了同样的错误。结果我在属性面板中的“NIB 名称:”下使用了 xib 文件的全名:
不要使用“SomeViewController.xib”,只需使用不带“.xib”扩展名的“SomeViewController”。
I had a similar problem and was getting the same error. Turns out I was using the full name of the xib file in the attributes panel under "NIB Name:"
Don't use "SomeViewController.xib", just use "SomeViewController" without the ".xib" extension.
我在调用
initWithNibName:@"MyViewController"
时遇到了同样的问题,将调用更改为
initWithNibName:NSStringFromClass([MyViewController class])
效果很好I had the same problem when invoking
initWithNibName:@"MyViewController"
Changing the invocation to
initWithNibName:NSStringFromClass([MyViewController class])
worked well您可以尝试以下操作:
You can try these things:
就我而言,xib 根本没有被复制到捆绑包中。一旦我将 xib 添加到应用程序目标的“复制捆绑资源”步骤中,一切就顺利了。
In my case, the xib simply wasn't being copied into the bundle. Once I added the xib into the "Copy Bundle Resources" step for the application target, everything went fine.
我终于设法通过以下两个步骤解决了该问题:
(仅用于测试)
我不知道为什么它在模拟器上工作:(
I finally managed to solve that issue with these two steps:
(just for testing)
I don't know why it works on the simulator :(
对我来说,问题正是 FreeAsInBeer 所说的那样:笔尖不知何故从捆绑包中丢失了,而它以前就在那里并且在应用程序的早期版本中正常工作。
为了解决该问题,我执行了以下操作:
当我收到这条消息时,这正是对我有用的。您的情况可能会有所不同,因为每个人的情况并不总是相同,但我希望这对遇到此问题的人有所帮助。
-埃文
For me, the problem was exactly what FreeAsInBeer said: the nib somehow was missing from the bundle, whereas it had been there before and worked properly in previous versions of the app.
To fix the problem, I did the following:
This is just what worked for me when I got that message. Your mileage may vary, since circumstances are not always the same for everyone, but I hope this helps someone who runs into this issue.
-Evan
我遇到了同样的问题。在我的例子中,笔尖名称是“MyViewController.xib”,我将其重命名为“MyView.xib”。这消除了错误。
我还将一个项目从 XCode 3 迁移到 4.2。更改路径类型并不重要。
I ran into the same problem. In my case the nib name was "MyViewController.xib" and I renamed it to "MyView.xib". This got rid of the error.
I was also moving a project from XCode 3 to 4.2. Changing the Path type did not matter.
我有同样的错误消息。
然而,我的问题是我手机上的语言设置为“英语”,区域设置为“英国”。然而,无法加载的文件被放置在de.lproj目录中。
将文件移动到根目录即可解决。
I had the same error message.
My problem, however was that my language settings on my phone were set on "English" and the Region on "United Kingdom". However, the file that could not be loaded was placed in the de.lproj directory.
Moving the file into the root directory solved it.
可能导致此错误的一个简单错误是当您使用情节提要而不是单个 Nib 文件时尝试在导入的 viewController 上 initWithNibName 。如果是这种情况,那么只需初始化控制器,而不是尝试使用不存在的 nib 进行初始化,或者使用 nil 来初始化这些字段。
如果 Storyboard 且没有笔尖,请将 initWithNibName:bundle: 更改为 init 或 initWithNibName:nilbundle:nil
A simple mistake that might cause this error is trying to initWithNibName on an imported viewController when you are using a storyboard rather than individual Nib files. If this is the case then just init the controller instead of trying to init with a nib that doesn't exist, or init those fields with nil.
If Storyboard and no nib, change initWithNibName: bundle: to just be init OR initWithNibName:nil bundle:nil
无论如何,当我的一个选项卡栏按钮分配了错误的类时,我收到了此错误。
For what its worth, I received this error when one of my tab bar buttons had the wrong class assigned to it.
我已经让它运行并从 xib 中删除所有本地化
在右侧窗口中。
也许该文件位于本地化文件夹中。
I've got it to run with delete all of the localization from the xib
In the right window.
Maybe the file is in the localization folder.
我有同样的问题。我的解决方案是删除视图的所有本地化。
I've the same problem. And my solution is remove all Localizations for the view.
我的行为正是您所描述的:在模拟器上工作,但在设备上运行时出现“无法在捆绑包中加载 NIB”,并且应用程序仍停留在启动图像上。
就我而言,问题在于 Xcode 使用英语本地化自动创建的 MainWindow.xib 文件。我在我的应用程序中支持英语和意大利语,并意识到我缺少意大利语的 MainWindow.xib 本地化版本。
因为我不需要本地化这个文件(Xcode 默认创建它本地化),所以我通过简单地删除英语本地化来解决这个问题,因此相同的文件独立于本地化使用。解决问题的另一种方法是添加缺少的本地化版本(如果需要)。
该应用程序在设备上崩溃,因为我的设备配置为意大利语。相反,模拟器被设置为英语,这就是应用程序正确运行的原因。为了验证,我将模拟器设置为意大利语,应用程序崩溃,确认了本地化问题。
I had exactly the behavior you described: works on simulator but get the "Could not load NIB in bundle" when running on the device, and the app remain stuck on the launch image.
In my case the problem was about the MainWindow.xib file that Xcode automatically created with English localization. I am supporting English and Italian in my app and realized that I was missing the localized version of MainWindow.xib for the Italian language.
Because I had no need to localize this file (it's Xcode default to create it localized) I fixed the problem by simply removing the English localization, so the same file is used independently of the localization. Another way to fix the problem would be to add the missing localized version, if you need it.
The app was crashing on the device because my device is configured for Italian language. The simulator instead was set to English and this is why the app run correctly. Just to verify, I set the simulator to Italian language and the app crashed confirming the localization problem.
当我从 initWithCoder 加载子视图控制器时也遇到了这个问题,这是一个初始化的好地方,但请记住,您必须在视图加载后将其添加为实际的子视图。
因此,将这样的内容移出:
...从 init 方法中移出并移至 viewDidLoad 中。并不是说这特别是您的问题,但这可能对其他人有帮助。
I also had this problem when I loaded a child view controller from initWithCoder, which is a good place to initialise, but keep in mind you have to add it as an actual child AFTER the view has loaded.
So shift something like this:
...out of your init method and into viewDidLoad. Not saying this is your problem in particular but this may be helpful to others.