无法打开故事板(com.apple.InterfaceBuilder 错误-1.)

10

我们的一个应用程序中有几个开发人员在制作故事板,现在当我们尝试在Xcode界面生成器中打开故事板时,会出现以下错误:

无法打开文档“MainStoryboard_iPhone.storyboard”。 操作无法完成。(com.apple.InterfaceBuilder error-1。)

请检查控制台日志以获取更多信息。

我们都运行最新版本的Xcode(4.6.2 4H1003),并且所有更改都是在Interface Builder中进行的。控制台日志中没有显示任何其他信息。我认为该错误是指与日志和调试语句出现的控制台日志相同,但它完全为空。

其中一个开发人员在另一个我正在工作的应用程序中尝试打开故事板时也会收到此错误。我可以在我的电脑上正常打开此故事板,因此我们当时从未费心去进一步研究此错误(这是几个月前首次出现)。但是这一次,我们全部遇到了同样的错误(我们四个都在自己的计算机上尝试打开它)。

我们使用GitHub管理两个项目的源代码控制,使用几个不同的Git客户端。有什么想法可以解决此错误以及如何修复它吗?

更新:这是在我的计算机上尝试打开故事板后的/var/logs/system.log输出:

Jun  5 16:38:44 my-computer-host-name Xcode[271]: Exception raised while unarchiving document objects - *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
Jun  5 16:38:45 my-computer-host-name Xcode[271]: [MT] DVTAssertions: Warning in /SourceCache/IDEKit/IDEKit-2113/Framework/Classes/Editor/IDEEditorDocument.m:1364
    Details:  Message sent to invalidated IBStoryboardDocument instance <IBStoryboardDocument: 0x40ecc34c0>. Backtrace for invalidation:
       0  0x000000010d814f86 -[IDEEditorDocument _invalidate] (in IDEKit)
      1  0x000000010d883291 -[IDEEditorDocument initForURL:withContentsOfURL:ofType:error:] (in IDEKit)
      2  0x00000001103005d0 -[IBDocument initForURL:withContentsOfURL:ofType:error:] (in IDEInterfaceBuilderKit)
      3  0x000000010d882efd +[IDEDocumentController _newEditorDocumentWithClass:forURL:withContentsOfURL:ofType:extension:error:] (in IDEKit)
      4  0x000000010d882dba -[IDEEditorContext _newEditorDocumentWithClass:forURL:withContentsOfURL:ofType:extension:error:] (in IDEKit)
      5  0x000000010d88290c -[IDEEditorContext _openNavigableItem:withContentsOfURL:documentExtension:shouldInstallEditorBlock:] (in IDEKit)
      6  0x000000010d991628 -[IDEEditorContext _notifyDelegateAndOpenNavigableItem:withContentsURL:documentExtensionIdentifier:locationToSelect:annotationRepresentedObject:stateDictionary:annotationWantsIndicatorAnimation:exploreAnnotationRepresentedObject:highlightSelection:] (in IDEKit)
      7  0x000000010d8bfe7b -[IDEEditorContext _notifyDelegateAndOpenEditorOpenSpecifier:updateHistory:] (in IDEKit)
      8  0x000000010d8bf99c -[IDEEditorContext _openEditorOpenSpecifier:updateHistory:] (in IDEKit)
      9  0x000000010d8bf8ba -[IDEEditorContext openEditorOpenSpecifier:] (in IDEKit)
     10  0x000000010d8cbf40 -[IDEEditorGeniusMode openEditorOpenSpecifier:editorContext:] (in IDEKit)
     11  0x000000010d8bf76e -[IDEEditorArea _openEditorOpenSpecifier:editorContext:takeFocus:] (in IDEKit)
     12  0x000000010d9a3174 __108+[IDEEditorCoordinator _doOpenEditorOpenSpecifier:forWorkspaceTabController:editorContext:target:takeFocus:]_block_invoke (in IDEKit)
     13  0x000000010d8bf6cc +[IDEEditorCoordinator _doOpenWithWorkspaceTabController:editorContext:target:allowFallback:documentURL:usingBlock:] (in IDEKit)
     14  0x000000010d8bf12d +[IDEEditorCoordinator _doOpenEditorOpenSpecifier:forWorkspaceTabController:editorContext:target:takeFocus:] (in IDEKit)
     15  0x000000010d8bed45 -[_IDEOpenRequest _runIfNecessary] (in IDEKit)
     16  0x00007fff8bfde395 __NSFireDelayedPerform (in Foundation)
     17  0x00007fff8b169804 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ (in CoreFoundation)
     18  0x00007fff8b16931d __CFRunLoopDoTimer (in CoreFoundation)
     19  0x00007fff8b14ead9 __CFRunLoopRun (in CoreFoundation)
     20  0x00007fff8b14e0e2 CFRunLoopRunSpecific (in CoreFoundation)
     21  0x00007fff8ac57eb4 RunCurrentEventLoopInMode (in HIToolbox)
     22  0x00007fff8ac57c52 ReceiveNextEventCommon (in HIToolbox)
     23  0x00007fff8ac57ae3 BlockUntilNextEventMatchingListInMode (in HIToolbox)
     24  0x00007fff85f5d563 _DPSNextEvent (in AppKit)
     25  0x00007fff85f5ce22 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] (in AppKit)
     26  0x00007fff85f541d3 -[NSApplication run] (in AppKit)
     27  0x00007fff85ef8c06 NSApplicationMain (in AppKit)
     28  0x000000010cbc9b6f (in Xcode)
     29  0x000000010cbc9b00 (in Xcode)
     30  0x0000000000000002

    Object:   <IBStoryboardDocument: 0x40ecc34c0>
    Method:   -updateChangeCount:
    Thread:   <NSThread: 0x40030a220>{name = (null), num = 1}
    Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide.

以下是另一个开发人员尝试打开我们在另一个项目中出现相同错误的故事板后在其计算机上的日志输出(这是在我的计算机上成功打开的故事板):

Jun  5 17:20:13 other-dev-computer-host-name Xcode[157]: Exception raised while unarchiving document objects - *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
Jun  5 17:20:13 other-dev-computer-host-name Xcode[157]: [MT] DVTAssertions: Warning in /SourceCache/IDEKit/IDEKit-2113/Framework/Classes/Editor/IDEEditorDocument.m:1364
    Details:  Message sent to invalidated IBStoryboardDocument instance <IBStoryboardDocument: 0x409ec3340>. Backtrace for invalidation:
       0  0x000000010d746f86 -[IDEEditorDocument _invalidate] (in IDEKit)
      1  0x000000010d7b5291 -[IDEEditorDocument initForURL:withContentsOfURL:ofType:error:] (in IDEKit)
      2  0x00000001102755d0 -[IBDocument initForURL:withContentsOfURL:ofType:error:] (in IDEInterfaceBuilderKit)
      3  0x000000010d7b4efd +[IDEDocumentController _newEditorDocumentWithClass:forURL:withContentsOfURL:ofType:extension:error:] (in IDEKit)
      4  0x000000010d7b4dba -[IDEEditorContext _newEditorDocumentWithClass:forURL:withContentsOfURL:ofType:extension:error:] (in IDEKit)
      5  0x000000010d7b490c -[IDEEditorContext _openNavigableItem:withContentsOfURL:documentExtension:shouldInstallEditorBlock:] (in IDEKit)
      6  0x000000010d7d9c96 -[IDEEditorContext _openNavigableItem:withContentsOfURL:shouldInstallEditorBlock:] (in IDEKit)
      7  0x000000010d8c3667 -[IDEEditorContext _notifyDelegateAndOpenNavigableItem:withContentsURL:documentExtensionIdentifier:locationToSelect:annotationRepresentedObject:stateDictionary:annotationWantsIndicatorAnimation:exploreAnnotationRepresentedObject:highlightSelection:] (in IDEKit)
      8  0x000000010d7f1e7b -[IDEEditorContext _notifyDelegateAndOpenEditorOpenSpecifier:updateHistory:] (in IDEKit)
      9  0x000000010d7f199c -[IDEEditorContext _openEditorOpenSpecifier:updateHistory:] (in IDEKit)
     10  0x000000010d7f18ba -[IDEEditorContext openEditorOpenSpecifier:] (in IDEKit)
     11  0x000000010d7f189f -[IDEEditorModeViewController openEditorOpenSpecifier:editorContext:] (in IDEKit)
     12  0x000000010d7f176e -[IDEEditorArea _openEditorOpenSpecifier:editorContext:takeFocus:] (in IDEKit)
     13  0x000000010d8d5174 __108+[IDEEditorCoordinator _doOpenEditorOpenSpecifier:forWorkspaceTabController:editorContext:target:takeFocus:]_block_invoke (in IDEKit)
     14  0x000000010d7f16cc +[IDEEditorCoordinator _doOpenWithWorkspaceTabController:editorContext:target:allowFallback:documentURL:usingBlock:] (in IDEKit)
     15  0x000000010d7f112d +[IDEEditorCoordinator _doOpenEditorOpenSpecifier:forWorkspaceTabController:editorContext:target:takeFocus:] (in IDEKit)
     16  0x000000010d7f0d45 -[_IDEOpenRequest _runIfNecessary] (in IDEKit)
     17  0x00007fff98955395 __NSFireDelayedPerform (in Foundation)
     18  0x00007fff909bd804 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ (in CoreFoundation)
     19  0x00007fff909bd31d __CFRunLoopDoTimer (in CoreFoundation)
     20  0x00007fff909a2ad9 __CFRunLoopRun (in CoreFoundation)
     21  0x00007fff909a20e2 CFRunLoopRunSpecific (in CoreFoundation)
     22  0x00007fff92e5eeb4 RunCurrentEventLoopInMode (in HIToolbox)
     23  0x00007fff92e5ec52 ReceiveNextEventCommon (in HIToolbox)
     24  0x00007fff92e5eae3 BlockUntilNextEventMatchingListInMode (in HIToolbox)
     25  0x00007fff96036563 _DPSNextEvent (in AppKit)
     26  0x00007fff96035e22 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] (in AppKit)
     27  0x00007fff9602d1d3 -[NSApplication run] (in AppKit)
     28  0x00007fff95fd1c06 NSApplicationMain (in AppKit)
     29  0x000000010caf9b6f (in Xcode)
     30  0x000000010caf9b00 (in Xcode)
     31  0x0000000000000002

Object:   <IBStoryboardDocument: 0x409ec3340>
Method:   -updateChangeCount:
Thread:   <NSThread: 0x40030a1a0>{name = (null), num = 1}
Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide.

两个日志输出非常相似。第二个输出在第6行中的调用堆栈中有额外的一行:[IDEEditorContext _openNavigableItem:withContentsOfURL:shouldInstallEditorBlock:] (in IDEKit)。而第11行(第一个输出中是第10行)引用了方法IDEEditorModeViewController而不是IDEEditorGeniusMode。除此之外,两个日志输出几乎完全相同。

请注意,我们最初在第二个故事板上收到这个错误,但是它不会因为Git合并冲突而出现问题,因为我是唯一一个在这个故事板上工作的开发人员。我从来没有需要在这个存储库中合并提交,因为我是唯一的贡献开发人员。


你能否检查之前的故事板版本,并在同一台电脑上使用相同的Xcode安装成功打开它? - rob mayoff
4个回答

40

正如Marcel所说:这有时会在合并时发生。但他的回答没有指出任何具体问题,所以让我给出一些提示,我们曾经处理过几次这样的问题。在本地更改了文件后,我们在文本模式下打开storyboard并检查结尾处的每个segue reference即可解决它们无法阅读的问题。

<inferredMetricsTieBreakers>
    <segue reference="gJw-Ph-JeV"/>
    <segue reference="Olp-GN-hLL"/>
    <segue reference="aFq-vB-ngK"/>
</inferredMetricsTieBreakers>

在Storyboard中搜索引用的值。如果找不到第二个匹配项,则使用<!-- -->进行注释。删除所有无效的segue引用后,Xcode可以再次打开storyboards。


这在我的情况下是问题所在。 - Basit ZIa
1
检查每个文本片段,例如“DPH-X9-4b0”是否可以被多次访问。 - WINSergey
你救了我的一天!谢谢你的提示!这正是发生在我身上的事情。 - mginius

6
这个项目使用了自定义字体吗?
我整整一天都在处理同样的问题(试过多台计算机和多个XCode版本),在安装了我们项目中的两个自定义字体后,Storyboard就能够打开了。
我收到了“invalidate”异常和数组异常的混合反馈。这个数组异常让另一位开发人员想起了一个类似的StackOverflow问题,他意识到我们有自定义字体。

这两个项目都将使用自定义字体。我们已经有一段时间没有遇到这个错误了,但如果再次看到它,我会记住这个提示的。谢谢。 - Jeff Lockhart
我已经确认这个修复解决了问题!谢谢。 - Jeff Lockhart
如果你没有注意到,这也意味着在Storyboard中支持自定义字体。终于! - Jakub

2
这个问题是由于合并 storyboard 更改引起的。Storyboard 格式基于 XML。当您进行更改时,这些更改将保存在项目文件中。Xcode 在保存此文件的结构方面似乎是不确定性的,内容可以按不同方式排序,对象可以出现在结构的不同位置。当您一个人工作时这没关系,但是当两个或更多人对 storyboard 进行更改时,合并可能会变得非常混乱。尽管 git 似乎能够很好地合并文件,但文件的结构会受到破坏,因此无法打开 storyboard。
请尽早提交并推送您对 storyboard 的更改。在对 storyboard 进行更改之前,请始终先拉取。不要合并,选择一个版本并继续。
您最好将 xcode 项目文件视为二进制文件存储在 git 存储库中。有关此内容的良好阅读,请参见http://robots.thoughtbot.com/post/33796217972/xcode-and-git-bridging-the-gap
至于您的情况,您可能需要检出已知的好的版本的项目文件,并从那里重新构建 storyboard 中的更改。

当我在两台不同的电脑上打开相同的Storyboard时,其中一台电脑能够正常工作,而另一台电脑却会出现相同的错误,这该怎么解释呢?此外,我要如何准确地查看XML结构中抛出错误的位置?我对这个结构的工作方式很了解,虽然这种错误总是很烦人,我们尽力避免它,但有时候在拉取分支并合并更改时必须使用。Interface Builder是否记录更多信息,例如发生错误的行数? - Jeff Lockhart
1
你确定两台电脑上的项目完全相同吗?此外,Xcode日志记录到/var/log/system.log。 - Marcel
是的,这些项目是相同的,从同一个代码库中拉取的最新版本。自几个月前我们第一次注意到错误以来,我们已经尝试了多次。每次我们都希望它能在另一个Xcode更新或其他任何事情上开始工作。我仍然可以继续编辑Storyboard。但是当另一个开发人员尝试在他的电脑上打开它时,他会得到相同的错误。 - Jeff Lockhart
谢谢你的帮助。我已经更新了我的问题,并附上了我们收到的日志输出。 - Jeff Lockhart
嗯,由于这些项目是相同的,也许可以开始排除其他用户相关的变量,这可能导致了这个问题。你可以尝试(逐个)删除用户偏好设置,删除xcode项目中的*.xcuserdatad目录并清除派生数据。此外,请检查您的.gitignore文件是否存在任何其他文件,在您的计算机和同事之间有所不同。 - Marcel

-1
这对我有用:
在出现错误的环境中删除.storyboard文件(移到废纸篓)。
从工作的环境中复制.storyboard并将其发送(单独的文件)到不工作的环境(电子邮件,U盘,Skype等)。
将.storyboard拖放回损坏的环境中(进行复制和保存)。
问题解决。

人们可能会对这个修复投反对票,但它依然能够正常工作。 - Yup.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接