iphone - 无法从 View Controller 手动加载 xib?

标签 iphone objective-c ios xib nsbundle

我正在使用 Blackboard SDK. 制作应用程序如果您可以下载 SDK 并查看是否有相同的错误,这将非常有帮助。
这是 instructions 的链接,以防有人想跟进——不要太多页面。

说明说

“因为模块在启动器应用程序中运行,所以 MainWindow.xib 文件是启动器的文件。因此,模块不能有自己的 MainWindow.xib 文件,因为它会产生冲突。

此外,当模块首次启动时,不会从 nib 文件中自动加载 View 。因此,从 nib 加载的所有 View 都必须在您的代码中手动加载,并且所有 nib 文件必须遵循相同的命名约定并包含在您的资源文件中。

最初,我试图像这样实例化一个 View Controller

   testVC = [[LMU_LAL_ViewControllerTest alloc] initWithNibName:@"LMU_LAL_ViewControllerTest" bundle:nil];

但是,它导致了崩溃。我收到的错误消息是
Could not load NIB in bundle: 'NSBundle </Users/mahir/Library/Application Support/iPhone Simulator/6.0/Applications/2ABAAF9D-5141-41B2-8EFB-51C3E047AD67/testLauncher.app> (loaded)' with name 'LMU_LAL_ViewControllerTest

有人说可以通过下载早期版本的xcode来解决这个问题,但这还没有帮助。另外,我将方法从 initWithNibName:bundle:init并将其添加到 View Controller 子类中
- (void)loadView
{
[super loadView];

UINib *nib = [UINib nibWithNibName:@"LMU_LAL_ViewControllerTest" bundle:nil];
[nib instantiateWithOwner:self options:nil];
} 

再次,我收到类似的错误,但这次在线[nib instantiateWithOwner:self options:nil]
我究竟做错了什么??

编辑:

这是支持团队的某个人给我的摘录。

All the resources used by your module, including any .xib files, MUST be included in the project of the LAUNCHER. This means that in the project that you are actually running to test the module, the launcher project, all of the resource files need to be included inside that project. An easy way to test if this is the case is to find your .xib files by looking on the left hand bar of Xcode in the launcher project. This will ensure that the resource files are actually getting included in the project. I have included a screenshot of what it should look like in the launcher project for Xcode.



enter image description here

这是我目前拥有的

enter image description here

最佳答案

从您对 Erfan 解决方案的回复来看,问题似乎只是文件 LMU_LAL_ViewControllerTest.xib 不在目标的构建阶段中。这意味着目标(您的程序)在构建时永远不会看到该文件,即使您可以在导航器中看到它。

将 xib 文件添加到目标的另一种方法是执行以下操作:

  • 在导航器 Pane 的顶部选择您的项目
  • 在导航器右侧的下一个 Pane 中选择目标
  • 打开Copy Bundle Resources : 你可能不会在这里看到 LMU_LAL_ViewControllerTest.xib,虽然它应该是
  • 选择+并从弹出窗口中选择文件添加

  • 如果这不起作用(可能不会,因为它相当于Erfan的解决方案),您可以尝试从项目中删除文件并将其重新添加。删除时,请确保Move to Trash .当您再次将其复制到项目中时,在出现的弹出窗口中,确保选中 Add to Targets 旁边的正确框.

    如果您的构建阶段缺少此文件,您可能会发现其他文件也丢失了,并且会触发类似的错误。您可以检查所有构建阶段,特别是其他资源文件的复制捆绑资源和 Objective-C 类的实现文件的编译源。

    关于iphone - 无法从 View Controller 手动加载 xib?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12592785/

    相关文章:

    ios - 如何在 Storyboard上为 xcode 中的所有设备定位按钮

    ios - 尝试从应用内发送电子邮件但不起作用 - Swift (iOS)

    c++ - 我可以添加自己的类型转换运算符以将 C++ 对象转换为 Objective-C 吗?

    android - 适用于 Android 和 iOS 的视频/音频框架

    ios - 如何使测验的答案标签在写出正确答案时显示正确,在写出错误答案时显示错误?

    ios - 请求被服务委托(delegate) (SBMainWorkspace) 拒绝

    iphone - TouchXML (Sudzc) 并正确使用这些数据

    ios - 方法泄漏中的对象

    ios - 我想在应用程序每 10 次快速打开时显示一条警报

    iphone - 在工具栏中添加自定义标签不起作用