我们有一个使用Storyboard的UIKit应用程序的Swift项目。一切都很好,直到我决定将应用程序的最低部署目标降低到iOS7。构建应用程序时,我在ibtool中命中了一个要编译情节提要的断言。错误是这样的:
2015-06-12 11:49:07.216 ibtoold[41058:6974134] [MT] DVTAssertions: ASSERTION FAILURE in /SourceCache/IDEInterfaceBuilder/IDEInterfaceBuilder-7702/InterfaceBuilderKit/Connections/IBConnection.m:182
Details: Source and destination must be unique
Object: <IBCocoaTouchStoryboardPushSegue: 0x7fdea9bce8a0>
Method: -setDestination:
Thread: <NSThread: 0x7fdea2c07820>{number = 1, name = main}
Hints: None
Backtrace:
0 0x00000001015e0147 -[DVTAssertionHandler handleFailureInMethod:object:fileName:lineNumber:assertionSignature:messageFormat:arguments:] (in DVTFoundation)
1 0x00000001015dfb9f _DVTAssertionHandler (in DVTFoundation)
2 0x00000001015dfe8e _DVTAssertionFailureHandler (in DVTFoundation)
3 0x00000001023ff472 -[IBConnection setDestination:] (in IDEInterfaceBuilderKit)
4 0x00000001023fe5c9 +[IBConnection connectionWithSource:label:andDestination:] (in IDEInterfaceBuilderKit)
5 0x00000001086aa798 (in IDEInterfaceBuilderCocoaTouchIntegration)
6 0x0000000108704abb (in IDEInterfaceBuilderCocoaTouchIntegration)
7 0x0000000102481472 -[IBDocument updateConnectionsAfterEnablingOrDisablingConfigurations] (in IDEInterfaceBuilderKit)
8 0x0000000102482194 __35-[IBDocument disableConfigurations]_block_invoke (in IDEInterfaceBuilderKit)
9 0x0000000102481beb -[IBDocument maintainCanvasCentersWhileTransformingCanvasPositions:] (in IDEInterfaceBuilderKit)
10 0x000000010248209c -[IBDocument disableConfigurations] (in IDEInterfaceBuilderKit)
11 0x000000010868852c (in IDEInterfaceBuilderCocoaTouchIntegration)
12 0x0000000102497469 -[IBDocumentAutolayoutManager runBlockInNewArbitrationStackEntryWithBehavior:block:] (in IDEInterfaceBuilderKit)
13 0x000000010247de2b -[IBDocument modifyViewsInAutolayoutSafeWayDuring:] (in IDEInterfaceBuilderKit)
14 0x00000001086884e2 (in IDEInterfaceBuilderCocoaTouchIntegration)
15 0x000000010865d1e5 (in IDEInterfaceBuilderCocoaTouchIntegration)
16 0x000000010244628f -[IBDocument finishChangingTargetRuntimeInCompiledIntermediateDocument] (in IDEInterfaceBuilderKit)
17 0x00000001024a5811 __85-[IBDocumentCompiler invokeWithIntermediateDocumentOfTargetRuntime:alwaysCopy:block:]_block_invoke (in IDEInterfaceBuilderKit)
18 0x00000001024a55a9 -[IBDocumentCompiler invokeWithIntermediateDocument:] (in IDEInterfaceBuilderKit)
19 0x00000001024a574d -[IBDocumentCompiler invokeWithIntermediateDocumentOfTargetRuntime:alwaysCopy:block:] (in IDEInterfaceBuilderKit)
20 0x00000001026aa61c -[IBStoryboardDocumentCompiler compileWithOptions:error:] (in IDEInterfaceBuilderKit)
21 0x00000001024a5937 +[IBDocumentCompiler compileContentsOfDocument:options:error:] (in IDEInterfaceBuilderKit)
22 0x0000000102460550 __47-[IBDocument compiledPackageWithOptions:error:]_block_invoke (in IDEInterfaceBuilderKit)
23 0x0000000102498ee5 -[IBDocumentAutolayoutManager assertIfArbitrationIsScheduledDuring:] (in IDEInterfaceBuilderKit)
24 0x00000001024604a7 -[IBDocument compiledPackageWithOptions:error:] (in IDEInterfaceBuilderKit)
25 0x00000001013e9f0a (in ibtoold)
26 0x00000001013e6b40 (in ibtoold)
27 0x00000001013e9370 (in ibtoold)
28 0x00000001013ef233 (in ibtoold)
29 0x00000001013ef7b0 (in ibtoold)
30 0x00000001013ef683 (in ibtoold)
31 0x00000001013de60a (in ibtoold)
32 0x00000001013eee2c (in ibtoold)
33 0x00000001013ee074 (in ibtoold)
34 0x00007fff9289f5c9 start (in libdyld.dylib)
35 0x0000000000000002
Command /Applications/Xcode.app/Contents/Developer/usr/bin/ibtool failed with exit code 255
我检查了所有segue(而且很多),但似乎没有发现任何错误。同样,当最小部署目标为8.x时,也没有问题。
最佳答案
注意-所有这些来自手动将引用出口添加到UI元素。不久之后,我发现我不需要这样做,仅需要添加TAG
即可,因为我只想能够以编程方式访问该元素以隐藏/显示它(Can I get the element by Tag from iPhone SDK?)。
无论如何...
不知道这是否一定适用于OP,但也许对Googler有帮助:
当我通过直接编辑.xib
的XML(而不是使用界面生成器)在情节提要中手动添加参考插座时,遇到了此错误。
原因:我想在我拥有的标签上添加引用出口。但是,当我在界面构建器中使用“新参考插座”时,我想要的IBOutlet
没有出现在列表中。因此,我采取了“用锤子砸直到它起作用”的方法,并决定在XML中手动添加引用出口。
参考出口看起来像这样:<outlet property="nameOfTheVar" destination="9CH-Ow-gWo" id="8CH-Ow-hWo"/>
destination
是UI元素的ID,这是它的出口,而id
是引用出口的唯一ID。<outlet>
应该是<connections>
元素的子元素(从某种意义上讲,它是将我的UI元素连接到IBOutlet
中的代码中)。我的<label>
具有<connections>
元素,因此我在此处添加了出口。 这就是导致我的源和目标必须是唯一错误的原因。我想它不希望插座成为该插座的元素的子代。
因此,为解决错误,我将<outlet>
从实际UI元素的子元素<connections>
元素移到了该视图的<connections>
的子元素<viewController>
元素。
这是(高度缩写)XML:
<viewController>
<layoutGuides />
<view>
<subviews>
<label id="9CH-Ow-gWo">
<connections>
<!-- dont put the outlet here -->
</connections>
</label>
</subviews>
</view>
<connections>
<!--put the outlet here! -->
<outlet property="nameOfTheVar" destination="9CH-Ow-gWo" id="8CH-Ow-hWo"/>
</connections>
</viewController>