xcode setValue:forUndefinedKey:]:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9950938/
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-09 04:21:09  来源:igfitidea点击:

setValue:forUndefinedKey:]:

xcodemodalviewcontrollerviewcontrollersigabrt

提问by Szwedo

FinalViewWithSending *newView = [[FinalViewWithSending alloc]initWithNibName:@"FinalViewWithSending" bundle:nil];
newView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:newView animated:YES]; //it crashes here with a thread 1 error, SIGABRT error..

It says:

它说:

"Terminating app due to uncaught exception 'NSUnknownKeyException', 
reason: '[<FinalViewWithSending 0x1bef70> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key loginButton.'"

There is no variable called loginButton so Im not sure why i am getting an error...

没有名为 loginButton 的变量,所以我不确定为什么我收到错误...

Thank you

谢谢

回答by Phillip Mills

You are getting the error becausethere is no property called loginButton. Check your .xib file. There is almost certainly a bad link to a FinalViewWithSending object (likely File's Owner) that specifies loginButton even though it doesn't exist in the class code.

您收到错误是因为没有名为 loginButton 的属性。检查您的 .xib 文件。几乎可以肯定有一个指向 FinalViewWithSending 对象(可能是文件的所有者)的错误链接,该对象指定了 loginButton,即使它在类代码中不存在。

回答by timquinn

Phillip Mills is correct.

菲利普米尔斯是正确的。

The answer here, for anyone searching, is to edit the storyboard and remove any link to the undefined key specified. You have to edit the storyboard file in an external editor: Right click on the storyboard listing in the hierarchy and then click on "show in finder" or what have you. Open in a text editor, remove said links by searching, save and return to Xcode. No more issue.

对于任何搜索者来说,这里的答案是编辑情节提要并删除指向指定未定义键的任何链接。您必须在外部编辑器中编辑故事板文件:右键单击层次结构中的故事板列表,然后单击“在查找器中显示”或您拥有的内容。在文本编辑器中打开,通过搜索、保存并返回到 Xcode 来删除所述链接。没有更多的问题。

This happens when you remove something from the view controller improperly.

当您不正确地从视图控制器中删除某些内容时,就会发生这种情况。

回答by Snowcrash

Agreeing here - Phillip Mills is correct.

同意这里 - 菲利普米尔斯是正确的。

Someone mentioned opening the storyboard up in a text editor - this isn't necessary.

有人提到在文本编辑器中打开故事板 - 这不是必需的。

Just click on the storyboard, go to the Connections Inspector. If you've got a problematic outlet, you'll see an exclamation marker next to the outlet. Delete it.

只需单击故事板,转到连接检查器。如果您的插座有问题,您会在插座旁边看到一个感叹号。删除它。

回答by Joshua Dance

Since this is the first search result for this error, I decided to write an answer for rookies like me.

由于这是这个错误的第一个搜索结果,我决定为像我这样的菜鸟写一个答案。

You are going to get this error if you have Ctrl dragged connections from Buttons which generates code in your ViewController and then you delete just the code without removing the connection.

如果您使用 Ctrl 键从 Buttons 中拖动连接,它会在您的 ViewController 中生成代码,然后您只删除代码而不删除连接,那么您将收到此错误。

I got this error because I had accidently added a few buttons as Outlets, when I wanted to add them as Actions. I deleted the code that got generated but the bad connections were still there.

我收到这个错误是因为我不小心添加了几个按钮作为 Outlets,当我想将它们添加为 Actions 时。我删除了生成的代码,但错误的连接仍然存在。

To find and remove them, View->Utilities->Show Connections Inspector

要查找并删除它们,请查看->实用程序->显示连接检查器

Then click through the different buttons you have and click the x to remove the bad connections.

然后单击您拥有的不同按钮并单击 x 以删除不良连接。

enter image description here

在此处输入图片说明

回答by Yan Arbanov

If you have any localizations, search for bad links in all the storyboards (expand storyboard to find localized storyboards).

如果您有任何本地化,请在所有故事板中搜索错误链接(展开故事板以查找本地化的故事板)。

This was my situation. I was looking for bad links in one storyboard and they were in the localized one.

这就是我的情况。我在一个故事板中寻找坏链接,它们在本地化的故事板中。

回答by James Wang

You can try the way I used to fix my setValue:forUndefinedKey:]:problem.

你可以试试我以前解决setValue:forUndefinedKey:]:问题的方法。

http://i.stack.imgur.com/PDjub.png

http://i.stack.imgur.com/PDjub.png

回答by kjbradley

I had the same problem:

我有同样的问题:

I had previously made a connection using storyboards from a textfield to a header file. I later decided I wanted to rename my object's connection, unfortunately, I didn't break the connection properly. If this problem was the same as mine, a connection existed to a button previously, and the code in the header was deleted, but the connection was not.

我以前使用故事板从文本字段到头文件建立了连接。后来我决定重命名对象的连接,不幸的是,我没有正确断开连接。如果这个问题和我的一样,之前有一个按钮的连接,header里面的代码被删除了,但是连接不是。

Check the object connections in the view you are segueing to.

检查您要转至的视图中的对象连接。

回答by iYoung

Go to the connection inspector of your xib of FinalViewWithSending view controller & remove the reference of login button. After that it will run. Try It... :)

转到 FinalViewWithSending 视图控制器的 xib 的连接检查器并删除登录按钮的引用。之后它将运行。尝试一下... :)

回答by Vikram Belde

Probably, you earlier created the LoginButton, Cmd+Shift+F and find the "LoginButton" and remove the Referencing Outlet and Re-build.

可能,您之前创建了 LoginButton,Cmd+Shift+F 并找到“LoginButton”并删除引用插座并重新构建。

回答by Scott Zhu

You can use associated objects to avoid subclassing. As for the setValue:forKey: and setValue:forUndefinedKey:, take a look in the header file (NSKeyValueCoding.h) for details.

您可以使用关联对象来避免子类化。至于 setValue:forKey: 和 setValue:forUndefinedKey: 详情请查看头文件(NSKeyValueCoding.h)。

According to your description, Find newView in your interface builder and right click it, you will see something like loginButton which is abnormal.

根据你的描述,在你的interface builder中找到newView,右击,你会看到loginButton之类的异常。