setValue:forUndefinedKey:]:
Asked Answered
D

12

21
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...

Thank you

Delisadelisle answered 30/3, 2012 at 21:59 Comment(1)
You haven't uploaded the code relevant to your error, please add it.Swaggering
P
35

You are getting the error because there 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.

Pyromancy answered 30/3, 2012 at 22:19 Comment(5)
There is not a bad link. I checked. Should I just create a loginButton variable?Delisadelisle
I don't know...if it were me, I'd rather find the actual error. What if you right-click FinalViewWithSending.xib, open it as source code, and search for the symbol as text? Sometimes things get weird in the xib in ways that don't show as UI elements in Xcode.Pyromancy
How do you open it as source code? I just went to source control and commit changes...I couldn't find it there either.Delisadelisle
If you control-click or right-click on the file name , you should get a menu that includes Open As and a sub-menu with a source code option.Pyromancy
Still nothing. I can't find loginButton anywhere in any file (I've checked everything). Any ideas? I can post the crash log if you guys want (the bold part of the console?) ThanksDelisadelisle
S
9

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.

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

Secretary answered 6/9, 2012 at 14:17 Comment(2)
It happened to me when I remained a UIImageView.Gaudy
For rookies here, you do not have to open a text editor and edit the storyboard. View->Utilities->Show Connections Inspector click on the different buttons so see the bad connectionBandaranaike
P
8

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.

Pulsatile answered 28/9, 2012 at 10:15 Comment(1)
Fixing problematic outlet solved my issue. Here is what I do, Click the ViewController which throws this error, Go to the Connections Inspector by going View->Utilities->Show Connections Inspector in Xcode 8.1 or simply ⌥⌘6.Dendrology
B
8

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.

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.

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.

enter image description here

Bandaranaike answered 17/9, 2017 at 5:35 Comment(0)
T
2

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.

Tahitian answered 7/9, 2012 at 13:36 Comment(0)
S
2

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

https://static.mcmap.net/file/mcmap/ZG-AbGLDKwfpKnMxcF_AZVLQamyA/PDjub.png

Sober answered 20/9, 2016 at 4:3 Comment(0)
D
1

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.

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

Dishevel answered 16/12, 2013 at 14:47 Comment(0)
B
0

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.

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

Boston answered 6/4, 2013 at 10:38 Comment(0)
C
0

Today I was working and I presented this same error, I used the response of Phillip Mills was correct and I had some labels in one ViewController.xib that were not being assigned links, i have five bad links, once assigned links, everything works perfectly, thanks answer of Phillip Mills.

Cattalo answered 22/7, 2013 at 22:32 Comment(0)
C
0

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... :)

Chinua answered 10/9, 2014 at 12:7 Comment(0)
S
0

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

Spurling answered 19/10, 2015 at 1:6 Comment(0)
T
0

This reply might be late relative to the time the question was asked but I just had this issue and I tried all solution posted here but none worked.

Here is my solution which could help anyone in the future.

Firstly the problem, :I used a custom cell class and made my connections, everything worked fine with my app then, I renamed my custom cell class ran my app but crashed with setValue:forUndefinedKey:] error.

My solution : Clicked .xib file, selected Identity inspector and typed the new named class in Custom Class -> Class tag. App error resolved.

Titmouse answered 8/10, 2019 at 17:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.