您的视图控制器可能在您的XIB中具有错误的类.
我下载了你的项目.
你得到的错误是
'NSUnknownKeyException', reason: '[<UIViewController 0x3927310> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key string.'
它是由MainWindow.xib
中具有102 instead of 103类的Second
视图控制器引起的.更改为正确的类可以解决问题.
顺便说一下,在Objective-C中使用类似"String"的名称是不好的做法.它会引发运行时命名冲突.即使是在一次性的练习应用程序中也要避免它们.命名冲突很难追踪,您不想浪费时间.
此错误的另一个可能原因是:将元素从一个控制器复制&;粘贴到另一个控制器时,Xcode会以某种方式保留与原始控制器的链接,即使在编辑&;将该元素重新链接到新控制器之后也是如此.
Another possible reason for this error:
插座坏了.
您的.h
文件中有removed或renamed个门店名称.
在.xib
或.storyboard
文件的连接判断器中删除它.
One more possible reason个
(在我的例子中)具有可绑定属性的UIView扩展,并设置这些可绑定属性的值(即阴影、拐角半径等)然后从UIView扩展中删除这些属性(出于某种原因),但以下<userDefinedRuntimeAttributes>
个保留在XML中(共foo.storyboard
个):
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="color" keyPath="shadowColor">
<color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="shadowOpacity">
<real key="value" value="50"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="point" keyPath="shadowOffset">
<point key="value" x="5" y="5"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="shadowRadius">
<real key="value" value="16"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="borderWidthValue">
<real key="value" value="0.0"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
Solution: Right click on foo.storyboard
> Open as Source Code > search by keyPath (i.e. shadowRadius) > Delete the </userDefinedRuntimeAttributes>
that causing the problem