xcode Interface Builder 无法打开文档“.xib”,因为它不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8968715/
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 23:04:15  来源:igfitidea点击:

Interface Builder could not open the document ".xib" because it does not exist

iphonexcodelocalizationxib

提问by MrSueko

I am localizing an app, following the steps listed here. I have successfully achieved that with around 45 .xib's, while just 4 of them gives me this error:

我正在按照此处列出的步骤本地化应用程序。我已经用大约 45 个 .xib 成功地实现了这一点,而其中只有 4 个给了我这个错误:

"Interface Builder could not open the document ".xib" because it does not exist."

“Interface Builder 无法打开文档“.xib”,因为它不存在。”

when I move them from their original position. I try to move them from their Project/Classes/Example.xib position to the localized one on Project/en.lproj/Example.xib.

当我将它们从原来的位置移开时。我尝试将它们从 Project/Classes/Example.xib 位置移动到 Project/en.lproj/Example.xib 上的本地化位置。

Why can't this .xib files be moved?

为什么不能移动这个 .xib 文件?

回答by Holger

For me it works like this:

对我来说,它是这样工作的:

  • select project target
  • remove the file from the build phasestab in copy bundle resources
  • re add it to the build phasestab
  • 选择项目目标
  • build phases选项卡中删除文件copy bundle resources
  • 将其重新添加到build phases选项卡

回答by jbiversen

I experienced the same error when running ibtools on .xib files in two different directories. It worked fine with the files in the first directory, but failed on the files in the second directory. If I swapped the order of processing the directories it still failed for the second directory.

在两个不同目录中的 .xib 文件上运行 ibtools 时,我遇到了同样的错误。它对第一个目录中的文件工作正常,但在第二个目录中的文件上失败。如果我交换了处理目录的顺序,它仍然无法处理第二个目录。

Finally I discovered that ibtool starts a demon process ibtoold that doesn't terminate when ibtool finishes, and if I killed that process I no longer got the error. Apparently the demon has some state that hinders ibtool in working in another directory.

最后我发现 ibtool 启动了一个恶魔进程 ibtoold,当 ibtool 完成时它不会终止,如果我杀死了那个进程,我就不再收到错误了。显然,恶魔有一些状态会阻碍 ibtool 在另一个目录中工作。

I used pkill ibtooldto kill the demon.

我曾经pkill ibtoold杀过恶魔。

回答by n8tr

I am having a problem using Xcode 5 that might be the same issue. ibtools is randomly working when generating or writing localized strings to/from xib files. I had to use sudo on some xib files to get it to work. Here's an example:

我在使用 Xcode 5 时遇到问题,这可能是同样的问题。ibtools 在生成或写入本地化字符串到/从 xib 文件时随机工作。我不得不在一些 xib 文件上使用 sudo 才能让它工作。下面是一个例子:

$ibtool --generate-strings-file en.lproj/MyVC.strings en.lproj/MyVC.xib
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"     
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.ibtool.errors</key>
<array>
    <dict>
        <key>description</key>
        <string>Interface Builder could not open the document "MyVC.xib" because it does not exist.</string>
    </dict>
</array>
</dict>
</plist>

Using sudo works although it complains about 'user domains will be volatile'

使用 sudo 可以工作,尽管它抱怨“用户域会不稳定”

$sudo ibtool --generate-strings-file en.lproj/MyVC.strings en.lproj/MyVC.xib
2013-10-01 10:04:35.943 Interface Builder Cocoa Touch Tool[1717:303] CFPreferences: user       
home directory at file:///var/root/Library/Application%20Support/iPhone%20Simulator/User/ is unavailable. User domains will be volatile.
$

回答by Andrei

To me this happened after a Git merge. The project file must have changed so much that now it gives all these errors. Those sensitive project files...

对我来说,这是在 Git 合并之后发生的。项目文件一定发生了很大的变化,现在它给出了所有这些错误。那些敏感的项目文件...

So anyway, what I ended up doing is just removing the files from the project (sending them to Trash) and then re-adding them to the project with a git checkout other_branch path/to/file

所以无论如何,我最终做的只是从项目中删除文件(将它们发送到垃圾箱),然后使用 git checkout other_branch path/to/file

After this, building the project did not throw this error anymore.

在此之后,构建项目不再抛出此错误。

  • It seems to work fine also if you remove just the reference and then re-add the file to the project (no need to send it to Trash)
  • ImportantYou should remove any red files from your Build Phases- Compile Sourcesof your target's settings. Those are files that XCode thinks are still there and thinks it should still try to compile, but when it doesn't find them, it gives back this error.
  • 如果您只删除引用然后将文件重新添加到项目中,它似乎也能正常工作(无需将其发送到垃圾箱)
  • 重要提示您应删除您的任何红色的文件Build Phases-Compile Sources你的目标的设置。这些是 XCode 认为仍然存在的文件,并认为它仍然应该尝试编译,但是当找不到它们时,它会返回此错误。