xcode 错误:由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[<UIApplication 0x6887a30> setValue:forUndefinedKey:]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9612426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:33:48  来源:igfitidea点击:

Error: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0x6887a30> setValue:forUndefinedKey:]

xcodeios4ios5

提问by Peter P

The full error is: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key.

完整的错误是:由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类不符合键值编码的键。

So I have been trying what other people have been saying with similar problems. I have tried getting rid of every mention of landscapeView in the project, including the Connections in the FIle's Owner in the ViewController_iPhone.xib and then I started fresh by making outlets in the super class ViewController (since I want to use landscapeView and portraitView for iPad also) then I set up connections in ViewController_iPhone.xib and ViewController_iPad.xib to the UIView named Landscape in each respectively, and I still get this error.

所以我一直在尝试其他人对类似问题所说的话。我已经尝试在项目中删除所有提到的 LandscapeView,包括 ViewController_iPhone.xib 中文件所有者中的连接,然后我通过在超类 ViewController 中创建插座来重新开始(因为我想在 iPad 上使用 LandscapeView 和 PortraitView也)然后我在 ViewController_iPhone.xib 和 ViewController_iPad.xib 中分别设置了到名为 Landscape 的 UIView 的连接,但我仍然收到此错误。

I'm just starting out in app development so I'm trying to make a template for an app that is supportive of all orientations on both iPhone and iPad. Thanks for any help

我刚刚开始应用程序开发,所以我正在尝试为应用程序制作一个模板,该模板支持 iPhone 和 iPad 上的所有方向。谢谢你的帮助

EDIT: Here is a link to all my app delegate h and m and main.m : I am getting the Applications are expected to have a root view controller at the end of application launch error

编辑:这是我的所有应用程序委托 h 和 m 以及 main.m 的链接:我得到应用程序预计在应用程序启动错误结束时有一个根视图控制器

EDIT 2: So I also tried to make landscapeView a property of ViewController and I made a setter method in ViewController.m but it still has the same problem.

编辑 2:所以我也尝试使 LandscapeView 成为 ViewController 的属性,并且我在 ViewController.m 中创建了一个 setter 方法,但它仍然存在相同的问题。

回答by Aaron

I've found the most common place this error happens is when you instantiate a view from a xib from within a class that is not the xib's owner.

我发现这个错误发生的最常见的地方是当你从一个不是 xib 所有者的类中的 xib 实例化一个视图时。

What I mean by this is you might be calling something similar to this:

我的意思是你可能会调用类似的东西:

[[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil];

You're changing the owner, so you have to be sure that the class that selfrefers to has all the IBOutlet properties needed by "MyView". Usually this is done in Interface Builder, but in this case you're setting your owner programmatically, which means you can't make the connections in IB. When the IBOutlets aren't there, the app tries to make those connections and fails, giving the error you see.

您正在更改owner,因此您必须确保所self引用的类具有“MyView”所需的所有 IBOutlet 属性。通常这是在 Interface Builder 中完成的,但在这种情况下,您以编程方式设置所有者,这意味着您无法在 IB 中建立连接。当 IBOutlets 不存在时,应用程序尝试建立这些连接并失败,并给出您看到的错误。

My advice (without knowing any more info than you've given so far) is to check to see if you've made this call without having the proper IBOutlets.

我的建议(不知道比您目前提供的更多信息)是检查您是否在没有适当的 IBOutlets 的情况下拨打了这个电话。

回答by jww

I had to remove the NIB or XIB (or whatever they are this iteration) for the Main Interface.

我必须删除主界面的 NIB 或 XIB(或它们是本次迭代的任何内容)。

It sure would be nice if Apple fully tested the broken software before unleashing it on the unsuspecting public. They could have handled the problem in any number of ways; but instead they chose a runtime crash and obscure [meaningless] error message.

如果 Apple 在将损坏的软件发布给毫无戒心的公众之前对其进行全面测试,那肯定会很好。他们可以通过多种方式处理问题;但相反,他们选择了运行时崩溃和模糊的 [无意义] 错误消息。

enter image description here

在此处输入图片说明

回答by Ravi Kumar

Two main reason is follow

两个主要原因是遵循

  1. your iboutlet may break please check in storyboard or IB.
  2. if you don't select module for custom class, see into your storyboard.
  1. 您的 iboutlet 可能会损坏,请检查 storyboard 或 IB。
  2. 如果您没有为自定义类选择模块,请查看您的故事板。

回答by idea2real

What I found is I deleted a WebView in viewcontroller.h , but haven't delete the xib file that point to this WebView !

我发现我在 viewcontroller.h 中删除了一个 WebView ,但没有删除指向这个 WebView 的 xib 文件!