无法在 Xcode 项目中创建新的 xib 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2231238/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:07:09  来源:igfitidea点击:

Can't create new xib files in Xcode projects

iphonecocoaxcodemacosinterface-builder

提问by Reed Olsen

This one is a doozy...

这是一个愚蠢的......

My buddy just downloaded the iPhone SDK on his Snow Leopard MacBook Pro. No matter what kind of project he creates (Window Based, View Based, etc...,) he can't create or use his own xib files. The project will compile and run fine until he adds a new xib file.

我的朋友刚刚在他的 Snow Leopard MacBook Pro 上下载了 iPhone SDK。无论他创建什么样的项目(基于窗口、基于视图等...),他都无法创建或使用自己的 xib 文件。该项目将编译并运行良好,直到他添加一个新的 xib 文件。

Here are some symptoms:

以下是一些症状:

  • When he selects a pre-generated xib in Xcode (such as MainWindow.xib), no preview is shown on the right hand side. Double clicking on this file will open it in interface builder (This is correct behavior).
  • When he selects his own custom xib, the preview pane displays the XML content of the xib. Double clicking on his custom xib opens up the XML file in Xcode - as if it were a standard code file (This is Hymaned up).
  • Opening his custom xib from finder opens it in Interface Builder.
  • When building the application, the build warning says something to the effect of "Warning: No rule to process file /path/to/CustomXib of type sourcecode.xib for architecture i386"
  • At runtime he gets the error:

    Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] was unable to load a nib named "MyCustomXib"'

  • 当他在 Xcode 中选择一个预先生成的 xib(例如 MainWindow.xib)时,右侧没有显示预览。双击此文件将在界面构建器中打开它(这是正确的行为)。
  • 当他选择自己的自定义 xib 时,预览窗格会显示 xib 的 XML 内容。双击他的自定义 xib 会在 Xcode 中打开 XML 文件——就好像它是一个标准的代码文件一样(这是被抬高的)。
  • 从 finder 打开他的自定义 xib 会在 Interface Builder 中打开它。
  • 在构建应用程序时,构建警告说明了“警告:没有规则可以处理架构 i386 的 sourcecode.xib 类型的文件 /path/to/CustomXib”
  • 在运行时,他收到错误:

    由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIViewController _loadViewFromNibNamed:bundle:] 无法加载名为“MyCustomXib”的笔尖

We've uninstalled Xcode from the command line and reinstalled. I've verified that it's the right version for his machine. I'm stumped!

我们已经从命令行卸载了 Xcode 并重新安装。我已经确认这是他机器的正确版本。我难住了!

采纳答案by Mark

Yes, I also had this problem and also upgraded directoy from Tiger to Snow Leopard. The fix for me was changing the file type of the nib file from sourcecode.xib to file.xib (control click on the nib file, select "Get Info", and modify the "File Type" in the dropdown.

是的,我也有这个问题,还把directoy从Tiger升级到了Snow Leopard。我的修复是将 nib 文件的文件类型从 sourcecode.xib 更改为 file.xib(控制单击 nib 文件,选择“获取信息”,然后在下拉列表中修改“文件类型”。

回答by TechZen

The error...

错误...

Warning: No rule to process file /path/to/CustomXib of type sourcecode.xib for architecture i386"

警告:没有规则来处理架构 i386 的 sourcecode.xib 类型的文件 /path/to/CustomXib"

... suggest the nib is for some reason in the "Compile Sources" build phase. Open the target and then open Compile Sources and see if the nib is listed there. If it is, move it to "Copy Bundle Resources" and try to compile again.

...建议笔尖出于某种原因处于“编译源”构建阶段。打开目标,然后打开编译源,看看笔尖是否列在那里。如果是,请将其移至“复制捆绑资源”并再次尝试编译。

回答by Reed Olsen

This is a total cop out, but after screwing around with Xcode, OS X, the terminal and seeing no progress, we've decided to wipe the machine and start fresh. The bug may be a consequence of upgrading directly from Tiger to Snow Leopard, and having some strange left-over settings.

这是一个彻底的警察,但在使用 Xcode、OS X、终端并没有看到任何进展之后,我们决定擦拭机器并重新开始。该错误可能是直接从 Tiger 升级到 Snow Leopard 的结果,并且有一些奇怪的遗留设置。

回答by Geir Haagensen

It seems my xib- file was saved with wrong file info when created by File->New_file->Create an UIViewController subclass in XCode.

在 XCode 中通过 File->New_file->Create an UIViewController 子类创建时,似乎我的 xib- 文件保存了错误的文件信息。

When I changed the file info into the same as for the MainWindow.xib, and also moved it from the Target compile folder, it worked fine; it both compiled and started in interface builder.

当我将文件信息更改为与 MainWindow.xib 相同的文件信息,并将其从目标编译文件夹中移出时,它工作正常;它在界面构建器中编译并启动。

PS: I too upgraded directly from Tiger to Snow Leopard, so that could be a candidate for mixing the settings of Xcode?

PS:我也直接从 Tiger 升级到 Snow Leopard,所以这可能是混合 Xcode 设置的候选?

回答by Dave DeLong

Try changing the file type of the xib from "sourcecode.xib" to "file.xib". "sourcecode.xib" seems like it would try to treat the file as a source file, and not as the (default) xib file.

尝试将 xib 的文件类型从“sourcecode.xib”更改为“file.xib”。“sourcecode.xib”似乎会尝试将该文件视为源文件,而不是(默认)xib 文件。