如何追踪 KVC 异常的来源:此类与按键工具栏的键值编码不兼容?

发布于 2024-08-31 00:03:35 字数 791 浏览 4 评论 0原文

当我尝试运行我的应用程序时,出现此错误:

2010-04-29 13:49:01.355 MyApp[56123:207] *** Terminating app due to uncaught
exception 'NSUnknownKeyException', reason: '[<MyViewController 0x5112b10>
setValue:forUndefinedKey:]: this class is not key value coding-compliant for 
the key toolbar.'

MyViewController 曾经有一个名为“toolbar”的 IBOutlet,它连接到中的 UIToolbar 对象一个笔尖。我决定不再需要工具栏或笔尖,因此我将它们从项目中删除了。但 Xcode 似乎仍然想引用“工具栏”。

如果我不再使用笔尖,对工具栏的引用可能在哪里?我可以合成一个虚拟的“工具栏”属性来安抚 Xcode,但我想避免这种丑陋的黑客行为。

编辑:奇怪的是,当我在设备而不是模拟器上运行代码时,没有引发异常。另外,当我对 MyViewController 使用一个简单的笔尖(不包含工具栏)时,异常消失了。我正在使用 git,当我返回运行 MyViewController 甚至有工具栏或笔尖之前的代码提交时,这些奇怪的也给出了异常。该代码过去运行良好。我确实认为这个异常与 Xcode 和模拟器以及我从项目中删除不需要的笔尖时留下的某种剩余状态有关。

I get this error when I try to run my app:

2010-04-29 13:49:01.355 MyApp[56123:207] *** Terminating app due to uncaught
exception 'NSUnknownKeyException', reason: '[<MyViewController 0x5112b10>
setValue:forUndefinedKey:]: this class is not key value coding-compliant for 
the key toolbar.'

MyViewController used to have an IBOutlet called 'toolbar' that connected to a UIToolbar object in a nib. I decided I no longer needed the toolbar or the nib so I removed them from the project. But Xcode seems to still want to refer to 'toolbar'.

Where might the reference to toolbar be if I no longer use a nib? I can synthesize a dummy 'toolbar' property to appease Xcode, but I want to avoid this kind of ugly hack.

EDIT: Strangely, the exception was not raised when I ran the code on the device rather than the simulator. Also, when I use a trivial nib for MyViewController (which contained no toolbar), the exception went away. I am using git and when I went back to run previous commits of my code from before MyViewController even had a toolbar or a nib, those strangely gave the exception as well. That code used to run fine. I do think this exception has something to do with Xcode and the simulator and some kind of left over state from when I removed the unwanted nib from the project.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月染过的梦 2024-09-07 00:03:35

Xcode 是一个 IDE。当您的应用程序运行时,并不是 Xcode 向您的视图控制器请求工具栏。

有两种方法可以解决此问题:

  1. 在 objc_exception_throw 上设置断点,然后在调试器下运行应用程序。
  2. -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] 上设置断点,然后在调试器下运行您的应用。

无论哪种方式,当异常发生时,调试器都会中断(中断)您的应用程序。查看堆栈跟踪以了解发送 valueForKey: 消息的内容。

Xcode is an IDE. It's not Xcode that's asking your view controller for a toolbar while your app is running.

There are two ways to troubleshoot this:

  1. Set a breakpoint on objc_exception_throw, then run your app under the debugger.
  2. Set a breakpoint on -[NSObject(NSKeyValueCoding) valueForUndefinedKey:], then run your app under the debugger.

Either way, the debugger will break (interrupt) your app when the exception happens. Look at the stack trace to see what sent the valueForKey: message.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文