20
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

pjumble
  • 16,880
  • 6
  • 43
  • 51
Szwedo
  • 354
  • 1
  • 3
  • 15

12 Answers12

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.

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57
  • There is not a bad link. I checked. Should I just create a loginButton variable? – Szwedo Mar 30 '12 at 22:27
  • 1
    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. – Phillip Mills Mar 30 '12 at 22:33
  • How do you open it as source code? I just went to source control and commit changes...I couldn't find it there either. – Szwedo Mar 30 '12 at 22:41
  • 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. – Phillip Mills Mar 31 '12 at 00:03
  • 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?) Thanks – Szwedo Mar 31 '12 at 03:28
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.

timquinn
  • 446
  • 4
  • 5
  • It happened to me when I remained a UIImageView. – Victor Engel Apr 15 '13 at 16:23
  • 2
    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 connection – Joshua Dance Sep 17 '17 at 05:31
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.

Snowcrash
  • 80,579
  • 89
  • 266
  • 376
  • 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**. – Fei Zheng Nov 26 '16 at 01:28
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

Joshua Dance
  • 8,847
  • 4
  • 67
  • 72
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.

Mahm00d
  • 3,881
  • 8
  • 44
  • 83
2

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

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

NSNoob
  • 5,548
  • 6
  • 41
  • 54
James Wang
  • 21
  • 1
  • 3
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.

kjbradley
  • 335
  • 2
  • 4
  • 20
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.

Scott Zhu
  • 8,341
  • 6
  • 31
  • 38
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.

juanmorillios
  • 63
  • 1
  • 5
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... :)

iYoung
  • 3,596
  • 3
  • 32
  • 59
0

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

Vikram Belde
  • 979
  • 8
  • 16
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.

Franklyn
  • 325
  • 2
  • 8