Xcode 4 中插座连接异常
我在 Xcode 4 中创建了一个新的 iPhone 项目,并从 Xcode 3 中创建的旧项目中添加了一些文件(xib 和类),该项目运行良好。
该项目编译良好,没有错误或警告。然而,当我尝试运行它时,我得到了臭名昭著的 “NSUnknownKeyException 原因:类与键 dateOutlet 的键值编码不兼容”错误。
当我打开 XIB 文件时,与 dateOutlet 的连接似乎很好,但为了安全起见,我还是删除并重新连接。下次我运行它时,我遇到了同样的错误,但在另一个插座上,这让我认为连接出了问题,我只需要再次重新连接它们。然而,我注意到有时当我重新连接插座时,我已经“修复”的插座会出现故障。经过大量摆弄后,我得出的结论是,重新连接并没有真正解决任何问题,只是当我对 xib 进行更改时,会随机选择下一个出现故障的插座(或者至少看起来如此)。
有人遇到过这个问题吗?我用谷歌搜索了很多,但似乎没有人遇到过这种确切的行为。我现在尝试在 3 台不同的机器上运行该项目,结果相同。
I have created a new iPhone project in Xcode 4 and added some files (xib and classes) from an old project which was created in Xcode 3 which works fine.
The project compiles fine with no errors or warnings. However, when I try to run it I get the infamous
"NSUnknownKeyException reason: class is not key value coding-compliant for the key dateOutlet" error.
When I opened the XIB file the connection to the dateOutlet seemed just fine, but I deleted and reconnected anyway just to be safe. Next time I ran it I got the same error but on another outlet which made me think that something went wrong with connections and I just needed to reconnect them again. However, I noticed that sometimes when I reconnected an outlet it would fail on an outlet which I had already ìfixedî. After a lot of fiddling I concluded that reconnecting didnít really fix anything, itís just that when I made changes to the xib the next failing outlet would be picked at random (or so it seems at least).
Has anybody experienced this problem? I have googled a lot but none seem to have encountered this exact behaviour. I have tried to run the project on 3 different machines now with the same result.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对象的类属性应该在 xib 文件中正确设置,
例如,如果您将 uiimageview 的 iboutlet 连接到 xib 中的 imageview 对象,请交叉检查该对象的类属性(通过按 command+4 打开) xib 设置为 UiImageview
The class property of the object should be set properly in the xib file,
for ex if you are connecting an iboutlet of uiimageview to an imageview Object in xib, cross check that the class property of that object(opened by pressing command+4) in xib is set to UiImageview
好的,我找到了问题的根源。似乎在应用程序的目标中,“主界面”被设置为我的 MainView,它是 UIView 的一个实例。我将其更改为 MainWindow(由 Xcode 生成)并且一切正常。
Ok, I found out the source of the problem. It seems that in the Target for the app the “Main Interface” was set to my MainView which is an instance of UIView. I changed it to MainWindow (generated by Xcode) and all worked fine.