Xcode - How to fix 'NSUnknownKeyException', Reason: "… this class is not key value coding-compliant for the key X" error?
Asked Answered
R

82

1322

I'm trying to link a UILabel with an IBOutlet created in my class.

My application is crashing with the following error"

*** 
Terminating app due to uncaught exception
'NSUnknownKeyException', reason: 
'[<UIViewController 0x6e36ae0> setValue:forUndefinedKey:]: 
this class is not key value coding-compliant for the key XXX.'

What does this mean & How can I fix it?

Riotous answered 21/6, 2010 at 19:57 Comment(11)
pedrotorres is right. Yes this is right. If you are doing a UITableViewCell, in IB remember to make teh File's Owner to NSObject, and the UITableViewCell'Class to the .h class you defined.Alleviate
When you encounter such an issue and the offending key is an action rather than an outlet then most probably you have an outlet which mistakenly references your action function name instead of your outlet variable name.Olid
You should notice that the name of the key in the error message (the OP is calling it 'XXXX') is the name you gave to something in your nib file. That's should help narrow down your search.Harsh
I filed rdar://22105925 asking Apple to make these errors more obvious at build time. :)Lehet
how to actually IMMEDIATELY SOLVE the problem! https://mcmap.net/q/23804/-setvalue-forundefinedkey-this-class-is-not-key-value-coding-compliant-for-the-key-duplicate fantastic tipTran
I had a custom table row controller class defined as a subclass of the wrong class. Another d'oh moment.Thamos
One other thing to watch out for is delegate classes. For example your view is of custom class X, but you are using it as an overlay for a UIImagePickerController, for which your controller is a delegate. Your controller will need to have properties for the outlets you referenced. I got caught by this recently.Triphylite
Okey so my problem had nothing to do with xib files, cause I actually do not use them in my project at all. I was just trying to add a key to an NSDictionary object and got this error. Turned out the way I was adding the objects to the NSDictionary was wrong.Castellany
I think this comment "If you are doing a UITableViewCell, in IB remember to make the File's Owner to NSObject, and the UITableViewCell'Class to the .h class you defined" needs to be another answer.Calliecalligraphy
In my case, it throws error because of Module in xib is different, I had copied the same xib from another target.Taber
the MODULE is a nightmare here ...Tran
T
1064

Your view controller may have the wrong class in your xib.

I downloaded your project.

The error you are getting is

'NSUnknownKeyException', reason: '[<UIViewController 0x3927310> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key string.'

It is caused by the Second view controller in MainWindow.xib having a class of UIViewController instead of SecondView. Changing to the correct class resolves the problem.

By the way, it is bad practice to have names like "string" in Objective-C. It invites a runtime naming collision. Avoid them even in once off practice apps. Naming collisions can be very hard to track down and you don't want to waste the time.

Another possible reason for this error: when copying & pasting elements from one controller into another, Xcode somehow keeps that link to the original controller, even after editing & relinking this element into the new controller.

Another possible reason for this error:

Bad Outlet.

You have either removed or renamed an outlet name in your .h file.

Remove it in .xib or .storyboard file's Connection Inspector.

One more possible reason

(In my case) Extension of UIView with bindable properties and setting values for those bindable properties (i.e. shadow, corner radius etc.) then remove those properties from UIView extension (for some reason) but the following <userDefinedRuntimeAttributes> remained in xml (of foo.storyboard):

<userDefinedRuntimeAttributes>
  <userDefinedRuntimeAttribute type="color" keyPath="shadowColor">
      <color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
  </userDefinedRuntimeAttribute>
  <userDefinedRuntimeAttribute type="number" keyPath="shadowOpacity">
      <real key="value" value="50"/>
  </userDefinedRuntimeAttribute>
  <userDefinedRuntimeAttribute type="point" keyPath="shadowOffset">
      <point key="value" x="5" y="5"/>
  </userDefinedRuntimeAttribute>
  <userDefinedRuntimeAttribute type="number" keyPath="shadowRadius">
      <real key="value" value="16"/>
  </userDefinedRuntimeAttribute>
  <userDefinedRuntimeAttribute type="number" keyPath="borderWidthValue">
      <real key="value" value="0.0"/>
  </userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>

Solution: Right click on foo.storyboard > Open as Source Code > search by keyPath (i.e. shadowRadius) > Delete the </userDefinedRuntimeAttributes> that causing the problem

Tippler answered 21/6, 2010 at 19:57 Comment(16)
Also do not forget to connect the "view" outlet of the nib to the file owner's view outlet (The view outlet of your custom class inherited from UIViewController). This can be done by control dragging from "File's Owner" under "Place Holders" to "view" under "Objects" and selecting the view outlet.Conglomerate
I've made sure all the class are already set, but the NSUnknownKeyException still comes out :(Romanaromanas
I'm not even using Interface Builder, and I'm still getting this error. Any idea what's going on?Violetvioleta
Never mind. It was because of two things: Xcode was still accessing my Main storyboard even though it was removed from the project, and the simulator had it cached. I highly unrecommend using storyboards or NIBs – they're ridiculously problematic.Violetvioleta
+1000 for what you say about bad naming practice. This is so obscure to figure out! I had a method called something like 'init....' and the application was crashing randomly all the time, then I renamed it and crashes just stopped.Titanothere
The problem in my case is sometimes -> User Defined Runtime Attributes. If you changed the class for control (and user defined attributes were meant for previous class), those attributes (non-existing for some other class) could throw just that exception.Undamped
@TheMuffinMan only 30 minutes? I have already lost one day of work because of this nonsense!Trunks
@Trunks Lol. Everytime I work up the motivation to create a native app in xcode it always ends with me spending a day trying to figure out how to do anything. I'm a c# dev so I've been looking at offerings from Xamarin and Telerik (nativescript) lately.Mild
Swift Language solves a lot of these problems by nailing everything down at compile time, but you lose the flexibility of Objective-C runtime.Coney
Turns out I was inheriting a subclass that already had an outlet for the object, meaning that it had essentially 2 outlets pointing to the same place, causing the crash.Business
I had the same issue but fixed it in different way. My project has different build configuration (pointing to different environment) which creates build with different bundle identifier. Somehow one of my cell's module (in Interface builder) was set to specific bundle identifier. I just set it to current-module to make it work. Setting none did not work.Cental
I would also like to point out a "bug" in Xcode that can insert these errors for you. If you make a connection by control-dragging into the class, and then notice that you made an outlet instead of an action (or vice versa), when you delete the code it leaves the connection behind. You have to manually disconnect it in the xib/sb editor.Gustatory
quoting: Another possible reason for this error: when copying & pasting elements from one controller into another, Xcode somehow keeps that link to the original controller, even after editing & relinking this element into the new controller. <= that was it for meCrenate
Make sure you select 'Inherit Module From Target' when using a custom view controller written in swift.Timi
What does xib stand for?Anaesthesia
If your issue still won't resolved and you have renamed your class file or nib file then double check in the "Build Phases" the correct file and path is linked with the project. OR delete the reference of the file and add it again.Supernova
I
1668

You may have a bad connection in your xib.

I've had this error many times. While TechZen's answer is absolutely right in this case, another common cause is when you change the name of a IBOutlet property in your .h/.m which you've already connected up to File's Owner in the nib.

From your nib:

  1. Select the object in IB and go to the 'Connections Inspector'.
  2. Under 'Referencing Outlets' make sure that your object isn't still connected to the old property name... if it is, click the small 'x' to delete the reference and build again.

    enter image description here

Another common cause if you are using Storyboard, your UIButton might have more then one assignings (Solution is almost the same as for nib):

  1. Open your storyboard and right click the UIButton
  2. You will see that there is more than one assign/ref to this button. Remove one of the "Main..." greyed windows with the small "x":

    example 2

Intratelluric answered 21/6, 2010 at 19:57 Comment(9)
Thanks! In my case I had 2 outlets to the same view, and getting rid of the old one and hooking up the view to the new one ended the exception.Redundant
mine was duplicated twice. I began disconnecting each one after i dragged and dropped from a Pro version ( from a Lite version ) thinking it was hanging onto connections in the other project. When i came across the duplicate, and it took 3 clicks to make the disconnection, i sincerely wished i done that 3 days earlier. Oh well- such is the life of a dev.Fredra
I had the problem that UIButton was having more than one assignings. This solved my issue.This
I had this problem too. Don't forget to check outlet connections in particular views instead of only superviews. In my case, superviews weren't showing the wrong connections =/Pierre
I had a similar error where I connected a button outlet to a the wrong ViewController swift file whose page would not have been created yet using the GUIMatch
What are the two icons (square spiral, resizing rectangle) to the right of the blue "Connections Inspector" (arrow in a circle) icon in the above answer. I note that the answer is from 2016 and that I'm asking this in 2018 but I don't recall ever seeing those icons before.Kannan
I got the same error In swift 4, xcode 9. I had copied a UILabel from one controller (cmd-c) and pasted it into another (cmd-v). Later I deleted the label from the second controller, but the outlet somehow didn't get removed. After deleting it (as shown in this answer), the error got resolved.Cardsharp
Have the same error over and over again, on diferents ways, even when I take the greatest care possible! I think is a bug on Xcode, is not possible that I messed up this ever time.Genista
In my case, that was added twice with different name. (y)Tabb
T
1064

Your view controller may have the wrong class in your xib.

I downloaded your project.

The error you are getting is

'NSUnknownKeyException', reason: '[<UIViewController 0x3927310> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key string.'

It is caused by the Second view controller in MainWindow.xib having a class of UIViewController instead of SecondView. Changing to the correct class resolves the problem.

By the way, it is bad practice to have names like "string" in Objective-C. It invites a runtime naming collision. Avoid them even in once off practice apps. Naming collisions can be very hard to track down and you don't want to waste the time.

Another possible reason for this error: when copying & pasting elements from one controller into another, Xcode somehow keeps that link to the original controller, even after editing & relinking this element into the new controller.

Another possible reason for this error:

Bad Outlet.

You have either removed or renamed an outlet name in your .h file.

Remove it in .xib or .storyboard file's Connection Inspector.

One more possible reason

(In my case) Extension of UIView with bindable properties and setting values for those bindable properties (i.e. shadow, corner radius etc.) then remove those properties from UIView extension (for some reason) but the following <userDefinedRuntimeAttributes> remained in xml (of foo.storyboard):

<userDefinedRuntimeAttributes>
  <userDefinedRuntimeAttribute type="color" keyPath="shadowColor">
      <color key="value" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
  </userDefinedRuntimeAttribute>
  <userDefinedRuntimeAttribute type="number" keyPath="shadowOpacity">
      <real key="value" value="50"/>
  </userDefinedRuntimeAttribute>
  <userDefinedRuntimeAttribute type="point" keyPath="shadowOffset">
      <point key="value" x="5" y="5"/>
  </userDefinedRuntimeAttribute>
  <userDefinedRuntimeAttribute type="number" keyPath="shadowRadius">
      <real key="value" value="16"/>
  </userDefinedRuntimeAttribute>
  <userDefinedRuntimeAttribute type="number" keyPath="borderWidthValue">
      <real key="value" value="0.0"/>
  </userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>

Solution: Right click on foo.storyboard > Open as Source Code > search by keyPath (i.e. shadowRadius) > Delete the </userDefinedRuntimeAttributes> that causing the problem

Tippler answered 21/6, 2010 at 19:57 Comment(16)
Also do not forget to connect the "view" outlet of the nib to the file owner's view outlet (The view outlet of your custom class inherited from UIViewController). This can be done by control dragging from "File's Owner" under "Place Holders" to "view" under "Objects" and selecting the view outlet.Conglomerate
I've made sure all the class are already set, but the NSUnknownKeyException still comes out :(Romanaromanas
I'm not even using Interface Builder, and I'm still getting this error. Any idea what's going on?Violetvioleta
Never mind. It was because of two things: Xcode was still accessing my Main storyboard even though it was removed from the project, and the simulator had it cached. I highly unrecommend using storyboards or NIBs – they're ridiculously problematic.Violetvioleta
+1000 for what you say about bad naming practice. This is so obscure to figure out! I had a method called something like 'init....' and the application was crashing randomly all the time, then I renamed it and crashes just stopped.Titanothere
The problem in my case is sometimes -> User Defined Runtime Attributes. If you changed the class for control (and user defined attributes were meant for previous class), those attributes (non-existing for some other class) could throw just that exception.Undamped
@TheMuffinMan only 30 minutes? I have already lost one day of work because of this nonsense!Trunks
@Trunks Lol. Everytime I work up the motivation to create a native app in xcode it always ends with me spending a day trying to figure out how to do anything. I'm a c# dev so I've been looking at offerings from Xamarin and Telerik (nativescript) lately.Mild
Swift Language solves a lot of these problems by nailing everything down at compile time, but you lose the flexibility of Objective-C runtime.Coney
Turns out I was inheriting a subclass that already had an outlet for the object, meaning that it had essentially 2 outlets pointing to the same place, causing the crash.Business
I had the same issue but fixed it in different way. My project has different build configuration (pointing to different environment) which creates build with different bundle identifier. Somehow one of my cell's module (in Interface builder) was set to specific bundle identifier. I just set it to current-module to make it work. Setting none did not work.Cental
I would also like to point out a "bug" in Xcode that can insert these errors for you. If you make a connection by control-dragging into the class, and then notice that you made an outlet instead of an action (or vice versa), when you delete the code it leaves the connection behind. You have to manually disconnect it in the xib/sb editor.Gustatory
quoting: Another possible reason for this error: when copying & pasting elements from one controller into another, Xcode somehow keeps that link to the original controller, even after editing & relinking this element into the new controller. <= that was it for meCrenate
Make sure you select 'Inherit Module From Target' when using a custom view controller written in swift.Timi
What does xib stand for?Anaesthesia
If your issue still won't resolved and you have renamed your class file or nib file then double check in the "Build Phases" the correct file and path is linked with the project. OR delete the reference of the file and add it again.Supernova
V
157

Sometimes this has to do with your "Inherit From Target" That value has to be set. With single target apps you can just select Inherit From Target. If you have more then one target select the desired target.

enter image description here

Vezza answered 21/6, 2010 at 19:57 Comment(8)
This answer helped me for a specific case. I have to continu working on an old obj-c project with multiple target. I create a custom UITableViewCell in Swift and I had the same error. By enabling "Inherit From Target" it worked. Thank you!Microprint
The module is not always set correctly; e.g. if you fill in the class name before actually creating the class.Spatterdash
I have filled the class name without pressing "Enter" key at the end so the IDE didn't checked this flag automatically. Wasted 1 hour on this. Thank you.Theisen
Never encountered this type of error in obj-c. But thanks its solved the mystery.Young
why is this burried in the 3rd page?Ploughman
Not sure @Ploughman perhaps it needs more upvotes. Share with your friends!Ambur
Man, thanks a lot!!! You've just made my day, i searched it for hours :( Thankkksss !!Intramundane
The error indicated in the original question was for a leaf control of a container with and was a secondary error to the earlier occurring error. The container wasn't inheriting from the target, and gave an error such as: Unknown class CustomUserClass in Interface Builder file.Discernible
T
130

I had this error when I was trying to implement a custom ViewCell for a table. When I highlighted View controller for the XIB and connected to the elements in the CellView caused the error " this class is not key value coding-compliant for the key" once I deleted these it got rid of the error.

Delete the connections in the below image. Delete the connections in inspector when File Owner is highlighted

Just make sure that you only have the connections with the Table View Cell. To check click on table view cell and in INSPECTOR look for your connections.

The connection should be in here when Table View Cell is highlighted

Toback answered 21/6, 2010 at 19:57 Comment(5)
This did it for me, thanks so much. I x'd out the connections when "File's Owner" was selected in the left column, then selected my custom cell and reattached them. Success!Guilford
Even with xcode7 this works, just use the right panel "Connections inspector". Remove the outlet from the tableviewcell and from the label, then re-add it and everything should work.Dumdum
This works but you need to make sure FileOwner didn't get set!! File owner should remain NSObject. #13793662Anvers
The same answer saved me twice!Winshell
Could someone please tell me what is the difference between set class name to File's Owner vs direct to UIView?Sirree
P
124

I had to delete the app from the simulator/iPhone to get rid of this error.

Pumphrey answered 21/6, 2010 at 19:57 Comment(5)
+1 this fixed it for me. I was cleaning up some code that used IB. When I deleted a button from the code the error kept popping up even when this button was not referenced at all in the nib files (at least that I could see).Afloat
I find this is necessary if you are debugging two applications that happen to have the same name.Infelicity
Yep, it seems that something from the XIB is cached on the simulator, which is a pain if you're testing upgrades since you actually don't want to have to delete the old app.Towne
I had this problem deleting my XIB file. This fixed the problem.Cinelli
If deleting app does not work, try deleting the XCode DerivedData folder. which can cache an incorrect xib file. Open XCode -> Preferences -> Locations -> Open the DerivedData folder and drag it to Trash.Hebetic
E
68

If it is an iPhone only app, not a universal one, make sure the following field is empty:

Targets > Summary > iPhone/iPod Deployment Info > Main Interface

If you specify an xib there it crashes.

Exocentric answered 21/6, 2010 at 19:57 Comment(6)
Yep, that was it for me. While flailing around to add a new startup view controller I set this to the new class/nib. After hooking up the view outlet I was hitting this error. Clearing this field fixed it.Foolproof
This worked for me. Note that I also had to delete the old version from the device/simulator for it to work.Curlpaper
Thanks - this was my problem. I had renamed my iPad storyboard file and did not update in my project's prefs.Sensitivity
Thank you! This solved it for me. (I had to delete the app from the simulator after changing the Main Interface field to be empty. Simply changing that field didn't force the simulator to break the cache.)Vidovik
I remembered that I changed things from a universal app to a iphone only app and this fixed the error!Mocha
This was my solution.Analcite
M
64

This error indicates that an already connected Interface Builder object is removed/renamed in its owner's source (File's Owner).

Control-click on the Files's Owner in the Interface Builder if you see a exclamation mark you need to fix that.

In the picture below you can see that "aRemovedView" has an exclamation mark on its right, that's because I removed the IBOutlet view object while it was already connected in the IB.

enter image description here

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

Magness answered 21/6, 2010 at 19:57 Comment(1)
Thank you! This fixed it for me. I've been having this issue for a long time and didn't know how to fix it other than starting over from scratch. This was it, deleted IBOutlets from the view controller, but didn't know they were still referenced/linked in the owner (in this case "View Controller" in interface builder - Xcode 6).Dieback
M
45

I had the same problem and while TechZen's answer may indeed be amazing I found it hard to apply to my situation.

Eventually I resolved the issue by linking the label via the Controller listed under Objects (highlighted in the image below) rather then via the File Owner.

Hope this helps.

enter image description here

Moskva answered 21/6, 2010 at 19:57 Comment(0)
Y
42

in my case it was an error in the storyboard source code, follow these steps:

  1. first open your story board as source code
  2. search for <connections>
  3. remove unwanted connections

For example:

<connections>
    <outlet property="mapPostsView" destination="4EV-NK-Bhn" id="ubM-Z6-mwl"/>
    <outlet property="mapView" destination="kx6-TV-oQg" id="4wY-jv-Ih6"/>
    <outlet property="sidebarButton" destination="6UH-BZ-60q" id="8Yz-5G-HpY"/>
</connections>

As you see, these are connections between your code variables' names and the storyboard layout xml tags ;)

Yttriferous answered 21/6, 2010 at 19:57 Comment(0)
T
36

enter image description here enter image description here

My fix was similar to Gerard Grundy's. In creating a custom UITableViewCell using an XIB, I had mistakenly applied the Custom Class name to the File's Owner instead of to the UITableViewCell. Applying the class to the UITableViewCell on the canvas and connecting my IBOutlet properties to it solved the issue.

Tarriance answered 21/6, 2010 at 19:57 Comment(2)
Ayyy dag nab it... Can't believe how often I make this mistake. Thanks lolIrreproachable
This also worked for me, but all the tutorials I watched say to set the file's owner to the class not the root view. I'm so confused on why this works in some cases, but not others?Allaround
J
34
  1. You only need to specify IBOutlet once, the IBOutlet label your ivar is unnecessary.
  2. Are you instantiating your NIB using your UIViewController? At some point you should be calling [SecondView initWithNibName:@"yourNibName" bundle:nil];
Joellenjoelly answered 21/6, 2010 at 19:57 Comment(3)
This helped! I was getting a key-value coding compliance error about a property from a different view controller. Turns out I was calling -initWithNibName with the wrong nib name.Muriate
Yes this helped me too.. i was using the UIViewController instead of MyCustomeViewController.. but this is kind of hierarchy issue may be.. the introspection failed because of the miss placed class object.. Thank you anywaysIselaisenberg
I had a similar issue. Two identical IBAction entries by accident. Didn't show in the code, only in the right-click of the UIControl (A UIStepper in my case). Just deleting one fixed it.Sackey
N
32

This was happening to me only when debugging on a device (iPhone). The iOS Simulator was working OK. Doing a "Product->Clean" from Xcode seemed to solve the problem, but I have no idea why.

Nanna answered 21/6, 2010 at 19:57 Comment(4)
This solve my problem. tsk2x almost 3 days of headache.Completion
It does provide an answer to the question. Something got messed up in Nib and doing a clean solved it. I read and tried all of the above to no avail and then did the clean, and after 1 hour of trying to fix it, Maj's solution fixed it. I would've loved to see what in the XML could've caused this but I've moved on.Abrahan
This does indeed solve the issue - I tried numerous suggestions above and only did the project clean fix this error that suddenly started occurring. Ugg...Wait
This fix my problem, I tried lot of above suggestions. Seems strange!Sutra
D
25

It can come from the fact that you have control dragged and created an outlet or action, and forgot to delete it. Even if you deleted the code, or even if you have made enough cmd+Z, you'll need to go in the connection inspector of your storyboard and see if the action or outlet you created is still here or not.

Dripdry answered 21/6, 2010 at 19:57 Comment(1)
Thanks! I'm a n00b on Xcode and took me a while to find the rogue links. In Xcode 9.2, you can right click on the element in the storyboard view and check the "Referencing outlets".Michaud
U
24

I had exact same error message and thanks (!!) to Kira from http://www.idev101.com I was able to solve the challenge. I only found her site after googling and stacking over all these threads. I'm now posting here for the next one that comes to StackOverFlow and has the same challenge I had since that person will most likely come to this thread over Google.

I realized, that I wrongly made this:

UIViewController *deviceViewController = [[UIViewController alloc] initWithNibName:@"DeviceViewController" bundle:nil];

Instead of THIS:

DeviceViewController *deviceViewController = [[DeviceViewController alloc] initWithNibName:@"DeviceViewController" bundle:nil];

Where

DeviceViewController

Was the name of my Class also known as

DeviceViewController.h 
DeviceViewController.m

You'll have to

"import DeviceViewController.h"

in your implementation (.m File) where you want to call e.g. another UIViewController.

I am absolutely not sorry if I am only stating the obvious for beginners like me and may get down votes as this is not exactly related to the question but I was searching 4 (?!?) hours straight now for the answer to these error message. If I can spare this to 1 or 2 people that'd be great :)

PS: For those interested in how the code continues for loading the other UIViewController:

    [self presentViewController:deviceViewController animated:YES completion:nil];
Unwilled answered 21/6, 2010 at 19:57 Comment(2)
THANKS for all the steps there, I was using Xcode 5 and didn't really know how to manually add a nib as you can only add storyboard by default.... I got some instructions but non as detailed as yours. Really helped!!Hinds
"I wrongly made this..." thanks, it's not the first time I spend a lot because of this really stupid mistakeOlodort
S
23

Looking over the other answers it seems like there are a lot of things that can cause this error. Here is one more.

If you

  • have a custom view
  • added an @IBInspectable property
  • and then later deleted it

Then you may also get an error similar to

Failed to set (xxx) user defined inspected property on [Your Custom View] ...: this class is not key value coding-compliant for the key [xxx].

The solution is to delete the the old property.

enter image description here

Open the Identity inspector for your class, select the property name under User Defined Runtime Attributes, and press the minus button (-).

Seaware answered 21/6, 2010 at 19:57 Comment(1)
I came so often on this page... This time this solution made it! But as weird as it sounds the old property to delete was actually on another ViewController than from the one it crashes, i have no idea why.Swage
B
16

This happens to me when my view controller originally had an .xib file, but now is created programmatically.

Even though I have deleted the .xib file from this project. The users iPhone/iPad may contain an .xib files for this viewcontroller.

Attempting to load an .xib file usually causes this crash:

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

Solution when creating it programmatically may be this:

-(void)loadView {
    // Ensure that we don't load an .xib file for this viewcontroller
    self.view = [UIView new];
}
Borscht answered 21/6, 2010 at 19:57 Comment(1)
I had converted my tab bar app from .xibs to .storyboard scenes. When I tried to implement a tab that presented a custom tableview it crashed with "Missing proxy for identifier storyboardPlaceholder". After hours of trying to fix, I found this post. As soon as I deleted the original .xib (now converted to storyboard scene) file from the project, the app quit crashing when the tableview tab was selected.Cristincristina
C
13

"Module" property of View Controller in the Identity Inspector might be different than what you expected. Also make sure that new classes are added to your target list.

Cavendish answered 21/6, 2010 at 19:57 Comment(1)
voting up since it was so in my case. I'm using Swift and Storyboards. When I created a new build target (to make a build variant) the app didn't work in the new variant while the first one worked OK. The app crashed on a View Controller where the module name was somehow set to module from the first target, while in working View Controllers it was Current - <module name here>. You need to erase the module name there in this case.Riva
A
12

I had a similar problem for a project that has two targets (with their own MainWindow XIB). The fundamental issue that caused this error for me was that the UIViewController class wasn't included in the second project's resource list. I.e. interface builder allowed me to specify it in MainWindow.xib, but at runtime the system couldn't locate the class.

I.e. cmd-click on the UIViewController class in question and double-check that it's included in the 'Targets' tab.

Artis answered 21/6, 2010 at 19:57 Comment(0)
B
9

"this class is not key value coding-compliant for the key" I know its a bit late but my answer is different so I thinks it needs to be posted, I was pushing the second controller in wrong way, Here is sample

Wrong Way to Push Controller

UIViewController* controller = [[UIViewController
 alloc]initWithNibName:@"TempViewController" bundle:nil];
         [self.navigationController pushViewController:controller animated:true];

Correct way

TempViewController* controller = [[TempViewController
 alloc]initWithNibName:@"TempViewController" bundle:nil];
         [self.navigationController pushViewController:controller animated:true];

I did not found any answer like above so may be it can help some one having same issue

Beginning answered 21/6, 2010 at 19:57 Comment(0)
R
9

Just to add to this, because I was getting this error as well. Going through all these answers most seem to apply to working with the UI and storyboard stuff. I know the original poster did seem to be working with the UI but when searching for possible reasons for this error mostly all questions lead back to this question with those others being closed as duplicates or simply having issues with connecting things in a storyboard so I will add my solution.

I was working on coding a web service in Swift 2. I had built all the needed proxy objects and stubs. As I looped through the returned XML I was dynamically instantiating my objects, which all came from NSObject and using setValue:forKey on them. Every time setValue:forKey tried to set a property it blew up with this error.

I had a switch statement for each type I was dealing with (e.g. Bool?, CShort?, String?) and for each XML node I went through and checked what the type was on the object and then converted the value to that type and attempted to set it with setValue:forKey.

Eventually I started commenting out all these setValue:forKey lines and found that my default switch statement case did work for String?.

I finally figured out that you can't use optional swift types with setValue:forKey unless they have a direct mapping to an Objective-C type like String? or NSNumber?. I ended up changing all CShort? types to NSNumber? since that has a direct mapping. For Bool? in my case it was fine for me to just use Bool and initialize it to false. Others may not have that luxury.

Anyway what a headache that was so hopefully this helps someone else who has a similar problem and keeps getting redirected to this question and saying to themselves, "I am not doing anything in UI!!".

So lastly to reiterate one more time Key-Value Coding does not work with optionals. Below I ended up finding somewhere but I forget where so to whoever posted this I apologize and would give credit if I remembered where I found this but it saved my life:

You cannot use KVC on an Optional Int property, because KVC is Cocoa / Objective-C, and Objective-C cannot see an Optional Int - it is not bridged to Objective-C. Objective-C can only see types that are bridged to Objective-C:

class types that are derived from NSObject

class types that are exposed with @objc

Swift structs that are bridged

Revoice answered 21/6, 2010 at 19:57 Comment(1)
If you are trying to connect a Swift bool value via Cocoa bindings, you need to expose it with @objc directive; otherwise you indeed get this error. This should be the best answer.Sagerman
H
8

I just had this issue in my duplicated project and solved by checking 2 places:

1- Make sure you have the .m file in the list -> Project - Build Phases - Compile Sources
2- After that, go to interface builder (probably this is an error occures with only IB) and unlink all properties, labels, images, etc... Then re-link all. I have realized that I've removed an attribute but it was still linked in IB.

Hope it works for some.

Horologist answered 21/6, 2010 at 19:57 Comment(0)
R
8

That might be the case of referencing a component from Xib Interface that you have renamed or delete. Re-referencing works for me.

Ruthenious answered 21/6, 2010 at 19:57 Comment(0)
C
7

In my case. I didn't have missing outlets in xib-files after merging.

Shift + Command + K

solved my problem. I cleaned my project and rebuilt.

Crownpiece answered 21/6, 2010 at 19:57 Comment(0)
I
7

This error is something else!

Here is how i Fixed it. I'm using xcode Version 6.1.1 and using swift. I got this error every time my app tried to perform a segue to jump to the next screen. Here what I did.

  1. Checked that the button was connected to the right action.(This wasn't the problem, but still good to check)
  2. Check that the button does not have any additional actions or outlets that you may have created by mistake. (This wasn't the problem, but still good to check)
  3. Check the logs and make sure that all the buttons in the NEXT SCREEN have the correct actions, and if there are any segues, make sure that they have a unique identifier. (This was the problem)
    • One of the segues did not have a unique identifier
    • One of the buttons had an action and two outlets that I created by mistake.
    • Delete any additional outlets and make sure that you the segues to the next screen have unique identifiers.

Cheers,

Instigate answered 21/6, 2010 at 19:57 Comment(0)
T
7

Another "not compliant" issue I found was when I managed to have two copies of a class for some reason.

I was adding keys to the wrong copy. Interface Builder still saw the keys and let me hook up to them, but at runtime it was using the other copy of the class that didn't have the new keys.

To find which was the "right" copy I used XCode's cmd-click on the class name elsewhere to jump to the correct copy, then I killed off the bad unused copies (after bringing over my edits from the un-used copy first).

Moral of the story: duplicate class files are bad.

Those answered 21/6, 2010 at 19:57 Comment(0)
S
6

If you have a custom UIViewController subclass with IBOutlets that are causing problems the only set of steps I found to actually get rid of the error were

.1 Change the class to UIViewController

.2 Disconnect all the outlets (they will all have the yellow warning triangle now) - it may be enough just to disconnect the problematic outlet(s).

.3 Do all the standard steps - ↑⌘K, delete Derived Data (, prayer mats, worry beads)

.4 Launch the app - go to the problematic scene.

.5 Kill the app, go back to Interface Builder change the class back to your custom class name.

.6 Reconnect your outlets.

Launch the app & this will normally have cleared up the key-value compliance issues.

Soneson answered 21/6, 2010 at 19:57 Comment(1)
This worked when copying and pasting a scene in the Storyboard editor.Lammastide
A
6

I had the same symptom. The root cause was that the "Target Membership" for my source file was not set to the correct target. I assume that means my class wouldn't get built and included in my app.

To correct it:

  1. Highlight your .m file.
  2. In the right pane, select the File Inspector.
  3. Under the "Target Membership" section, make sure the appropriate build target is checked.

Hope this helps somebody out there.

Afro answered 21/6, 2010 at 19:57 Comment(0)
B
5

In my case it was the module that was specified to the wrong target. Simply deleting the module name and checking Inherit Module from target did the trick.

enter image description here

Bindle answered 21/6, 2010 at 19:57 Comment(0)
M
4

In my case, this was caused by referencing the wrong Nib:

BMTester *viewController = [[BMTester alloc] initWithNibName:@"WrongNibName" bundle:nil];
Morganne answered 21/6, 2010 at 19:57 Comment(1)
Happens to me when I rename the view controller's class and forget that the the nib name needs to change too. Since the nib name is just a string, there's no compiler error.Harsh
E
3

iOS Run Time Error

Thread 1: "[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key xxx."

You can get this error when:

  1. .xib + UITableViewHeaderFooterView

When you work with UITableView where show header/footer which extends UITableViewHeaderFooterView and connect with .swift file and

  • set File's Owner

correct way:

  • set Custom Class for containerView instead
  1. Check Outlets in .xib. Some of them can be marked by Xcode using yellow explanation mark. In this case just resetup it
Excurvature answered 21/6, 2010 at 19:57 Comment(0)
R
3

You may have outlets to UI Element but not IBOutlet property in .h File

For all UI element in Connection Attribute check outlets and it corresponding property in .h header file.

May be missing one or more property entry in .h file.

Renwick answered 21/6, 2010 at 19:57 Comment(0)
C
3

I had the same kind of problem. I created a tableviewCell in a XIB file and was getting that kind of error. My problem was that I defined the "File's Owner" class to be my cell view controller. I just took it out and set the cell's class (on the xib file click the border of the cell, go to the third tab on the right panel and where it says class chose your view controller).

Also try cleaning your code.

Carsoncarstensz answered 21/6, 2010 at 19:57 Comment(0)
E
3

I got the same problem. I did resetting the simulator. Removing and adding button control. and finally made a clean. :) Thanks to stack overflow. Some how my code became ok and starting working.

Ehrsam answered 21/6, 2010 at 19:57 Comment(0)
W
3

I was getting this error with storyboards. The above solution didn't seem to be the problem so I ended up deleting the view controller and adding it back in again (and of course reconnecting the segue and reassigning the class) which fixed it. I don't know what it really was, but I had renamed the associated view controller class shortly before this started, so maybe that had hosed something.

Woke answered 21/6, 2010 at 19:57 Comment(1)
I got this error again. This time I created a new empty table view controller with my class assigned to it, leaving the non-working one alone, and moved the segue to it. This worked. I then slowly copied every element in the view over until it failed again. This time the problem turned out to be I had assigned some "User Defined Runtime Attributes" for a picker (I was thinking I could use them to initialize the picker so I wouldn't have to do it in code, no idea if that's possible). Removing that fixed the problem. This error is really horrible, I hope it's improved in a future release!Woke
A
2

I also had this problem, it was due to renaming a view by creating a new outlet to it. Your might have the old connection outlet in the storyboard.

What you need to do is to remove the old outlet from the storyboard.

  1. Goto the storyboard.
  2. Click "Show Code Review" button (the one the <- -> sign on it, just left of the show/hide navigator).
  3. Search for the "connections" tag.
  4. Look for the "outlet" tag within the "connections" tag with the "property" attribute set to the name you are getting in the Exception.
  5. Remove that outlet tag.
  6. Hit "Command + B", Enjoy!
Andreasandree answered 21/6, 2010 at 19:57 Comment(0)
S
2

I got the same error when I manually loaded a view from a nib. It turns out that I had forgotten to set the view's owner.

For e.g. If you load a view in the following way,

 let view = Bundle.main.loadNibNamed("MyNibFileName",
                                 owner: nil,
                                 options: nil)?.first as! UIView

and then add an IBOutlet, the IBOutlet can't be referenced and the application will crash with the above error.

Fix: Assign an owner for the view.

 let view = Bundle.main.loadNibNamed("MyNibFileName",
                                 owner: self,
                                 options: nil)?.first as! UIView
Scalf answered 21/6, 2010 at 19:57 Comment(0)
L
2

I resolved this problem by doing 2 things:

  1. Fixed Class reference of the view:

  1. Reimported all Outlets:

Lamere answered 21/6, 2010 at 19:57 Comment(0)
E
2

In my case it was that an IBOutlet's property name in a ViewController.m was changed, but the one in Storyboard was not. Reintroducing the IBOutlet into the ViewController.m per ctrl-drag solved the problem. I have also noticed a way to find such "orphane" IBOutlets in XCode: (look at the image) the ones that are not "orphaned" have concentric circles instead of line numbers.

"Orphaned" IBOutlets don't have concentric circles in the line number column.

Extraction answered 21/6, 2010 at 19:57 Comment(0)
N
2

I had this problem with storyboard and swift class for ui view controller. Solved it by using the @objc directive:

@objc(MyViewController) class MyViewController
Numberless answered 21/6, 2010 at 19:57 Comment(0)
T
2

You may need to delete the outlet , recreate it by drawing form IB to .H file.

Tedmund answered 21/6, 2010 at 19:57 Comment(0)
R
2

I had the same issue.This happened with my project because I changed my product name but in interface builder I had the old name as Module, this leads to crash so be sure to check all the xib module name also has been changed or not.

Rosetta answered 21/6, 2010 at 19:57 Comment(0)
R
2

This also happens to me when an UI label or other UI element is referenced by two variables in the view controller class and I delete one of the variable.

Rhodes answered 21/6, 2010 at 19:57 Comment(0)
S
2

I deleted the property from the header file. I couldn't find any reference to it but the debug error was still referencing it. I found that the nib file still had a reference to it. I deleted the block that referenced it and everything was fixed.

In Project Navigator,

Find the Nib (xib) file. Right click and View Source. I deleted the the following full section

<object class="IBConnectionRecord">
    <object class="IBCocoaTouchOutletConnection" key="connection">
        <string key="label">DeleteLabel</string>
        <reference key="source" ref="372490531"/>
        <reference key="destination" ref="774585933"/>
    </object>
    <int key="connectionID">20</int>
</object>
Sybaris answered 21/6, 2010 at 19:57 Comment(0)
H
2

Check if you have stray Referencing Outlets by selecting the offending object in the Storyboard/xib interface and opening the Connections Inspector (View->Utilities->Show Connections Inspector). If you do remove the unwanted connections and you should be good to go.

Honest answered 21/6, 2010 at 19:57 Comment(0)
A
1

In my case, I forgot to input the Module of my ViewController inside Custom Class section (located in the right hand side of the storyboard screen)

Afghan answered 21/6, 2010 at 19:57 Comment(0)
U
1

For me it, I had to click the file's Owner object and navigate to connections and removed the problematic connections

Unscratched answered 21/6, 2010 at 19:57 Comment(0)
Q
1

To add to this epic saga of a thread...

My view controller had an attribution above it: @objc(TheNameOfMyViewController)

This made all the Outlets crash with "not key value compliant" error for each Outlet. This was only an issue on IOS12 and below. It worked fine on iOS 13.

Removing that modifier fixed this problem. All the outlets are working fine now.

Quarterdeck answered 21/6, 2010 at 19:57 Comment(0)
C
1

I encountered this error that occurred on all outlets in a custom class I had created for a table view prototype cell. The outlets were all correctly connected to the storyboard, and the Class field was correctly named in the identity inspector for the prototype cell.

Deleting and recreating the outlets did not work. Cleaning the build did not work. What finally worked was to change the Class in the storyboard identity inspector to the default UITableViewCell, hit Enter, then change it back to the name of my custom class afterwards. For some reason, this worked.

Coypu answered 21/6, 2010 at 19:57 Comment(0)
R
1

My problem started after i changed the Target name.

My own custom UI classes had the Module name set to the old target name.

I changed the target name to the new one and it works fine now.

Remorse answered 21/6, 2010 at 19:57 Comment(0)
N
1

I had the same issue, and the cause was due to specifying a Module in Interface Builder (as opposed to leaving it blank). So, when I was using either a different module than the one I set, the app would crash :S ... hope this helps someone else, as my issue was not due to a broken or out-of-date outlet!

Nape answered 21/6, 2010 at 19:57 Comment(0)
A
1

It could mean you're trying to use a sort descriptor without an atsign at the beginning. As in:

[array valueForKeyPath:@"distinctUnionOfObjects.self"]

Which must actually be:

[array valueForKeyPath:@"@distinctUnionOfObjects.self"]

Ardeb answered 21/6, 2010 at 19:57 Comment(0)
B
1

I ran into the same problem for a different reason: I was using the main storyboard as the launch screen file. I guess if you are using a storyboard as the launch screen file, it shouldn't be connected to the view controller as it won't have been loaded yet.

Bony answered 21/6, 2010 at 19:57 Comment(0)
B
1

I had the same issue when I was using the main storyboard as the launch screen file. I guess if you are using a storyboard as the launch screen file, it shouldn't be connected to the view controller as it won't have been loaded yet.

Bony answered 21/6, 2010 at 19:57 Comment(0)
J
1

I had this happen when i had a UIView linked into a storyboard and connected IBOutlet like:

@property (strong, nonatomic) IBOutlet UIView *someView

but later on, i made the UIView into a custom class but forgot to change the class name of this IBOutlet defined above. its a strange error because if the custom view has no subviews it doesnt complain, but as soon as there are subviews it shows the error stated in the question but on one of the subviews and not the outer UIView where the problem actually exists. had me deleting and readding all the subviews trying to find the problem, when in fact had nothing to do with the subviews

Juttajutty answered 21/6, 2010 at 19:57 Comment(0)
C
1

Along with other issues that you can see in other answers. The way I created this error for myself was that I started a project from scratch and begin by deleting the initial scene of my storyboard and then pasted a scene from another project into my storyboard.

There is no problem in doing that. You only need to add an entry point of your storyboard i.e. check the is initial View Controller on which ever view controller you like. Otherwise it will be a gray scene and throw you an error.

enter image description here

Chemotaxis answered 21/6, 2010 at 19:57 Comment(0)
N
1

I had this problem with swift classes after upgrading to xcode7. Solved it by using the @objc directive:

@objc(XXXViewController) class XXXViewController

Numberless answered 21/6, 2010 at 19:57 Comment(0)
C
1

Sometimes swift file are not added or removed from target, go to target-->Build setting --> compile Sources --> see if any required swift class file is missing or not . In my case Application was crashing due to swift source file not present in compile.

Clipped answered 21/6, 2010 at 19:57 Comment(0)
S
1

This has already happened to me twice.

The solution was remaking the whole storyboard since I copied it from another one (because it was almost the same)

Slier answered 21/6, 2010 at 19:57 Comment(0)
H
1

In my case,

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

was the reason.

replacing this with initWithNibName, resolved.

Hyphenate answered 21/6, 2010 at 19:57 Comment(0)
B
1

Another one cause of this situation is that you declare this property implemented as @dynamic, but class can not find it in parent class.

Bootjack answered 21/6, 2010 at 19:57 Comment(0)
K
1

Same issue presented. My solution was to put the correct storyboard value in the Main Storyboard drop down. I had renamed mainstoryboard.storyboard, but not reset the deployment info.

Katakana answered 21/6, 2010 at 19:57 Comment(0)
K
0

As far as I'm concerned I stupidly changed the access modifier of my UIViewController to Private and of course it couldn't access it...

Kolnos answered 21/6, 2010 at 19:57 Comment(0)
E
0

This thread is really an epic saga as @FranticRock mentioned.

In my case -

  1. the outlets are properly connected
  2. the "Inherit From Target" has a proper value which means the module is properly added

What caused the crash in my case is User Defined Runtime Attributes under the Identity Inspector

I have a view that somehow had three attributes borderColor, borderWidth and cornerRadius

enter image description here

Removing these attributes from that view resolved the issue.

Erinerina answered 21/6, 2010 at 19:57 Comment(0)
P
0

enter image description here

Remove button reference by clicking the button and then re-create reference to this button.

Poland answered 21/6, 2010 at 19:57 Comment(0)
E
0

NSUnknownKeyException error

'NSUnknownKeyException', reason: this class is not key value coding-compliant for the key

I got this error when .xib file(e.g. TableViewCell.xib) had the same name as cell class(e.g. TableViewCell.swift)

The correct approach is:

TableViewCell.swift -> View.swift <-> View.xib
Excurvature answered 21/6, 2010 at 19:57 Comment(0)
A
0

I tried literally every option in this thread. The only thing that fixed it for me was changing the name of my custom view xib file.

My custom view and xib had the same name. Renaming the xib fixed it.

Affinity answered 21/6, 2010 at 19:57 Comment(0)
C
0

I am using the Xamarin.IOS to create the custom nib. Finally I found the root cause, went to Xcode and selected the nib file, In the Interface Builder, choose the UIView class and select the Connections Inspector and remove the default outlets as shown below.enter image description here

Conventioner answered 21/6, 2010 at 19:57 Comment(0)
S
0

Really stupid mistake with me. So I decided to share here, hope this will help another people like me.

I have another submodule in my project, and I name a new class with same name with another class in main module, my new class NOT have xib file(100% by code), but another class in main module have xib file. I think Xcode linked wrong the new class with the xib file in main module.

That the reason for crash with message:

this class is not key value coding-compliant for the key tableView.

Sirree answered 21/6, 2010 at 19:57 Comment(0)
N
0

In my case, I had added a ViewController to the storyboard, but I didn't assign it a Storyboard ID in the designer. Once I gave it an ID, it worked.

using Xamarin/Visual Studio 2015.

Neumann answered 21/6, 2010 at 19:57 Comment(0)
F
0

Make sure you add the custom class' (even empty) implementation in the .m file like:

@implementation MySubclass
@end
Franko answered 21/6, 2010 at 19:57 Comment(0)
H
0

The cause of my trouble, was that I duplicated a storyboard file (outside of Xcode if I recall correctly), then all view controllers in the duplicated file had same object-ID as in the original file. The remedy is to copy-pasted the view controllers, and they will then get a new object-ID. You can see the object-ID in the Identity Inspector.

Hypnotic answered 21/6, 2010 at 19:57 Comment(0)
O
0

Just pay attention if you're trying to observe a value that doesn't exist.

This happened to me simply as I was observing the "Text" property of a text field when I was supposed to be observing the "text" property instead.

Overtask answered 21/6, 2010 at 19:57 Comment(0)
L
0

Did you leave your picker object unconnected?

lol 54 answers and not one of them is my solution. Talk about a common error.

In my case it was because I had a picker object on my VC and had not set an outlet and action for it.

I often leave buttons etc unconnected when I am just looking to see how the layout looks. But it seems you cannot do this for a picker.

Linzer answered 21/6, 2010 at 19:57 Comment(0)
P
0

Another tricky case:

In IB added ViewController to storyboard, deleted its view and set Custom Class to "MyViewController" so view is instantiated from MyViewController.xib

Specifying Storyboard ID the same "MyViewController" causes exception.

Changing Storyboard ID to some different name resolves the issue.

Prevot answered 21/6, 2010 at 19:57 Comment(0)
M
0

I had this problem too. I had copied a view with an IBOutlet from one xib file to another xib file. And even though I had removed the old reference and create a new reference, this error was still occurring.

I ended up restarting xcode to fix this problem.

Mcwilliams answered 21/6, 2010 at 19:57 Comment(0)
C
0

I had the same error in yet another slightly different form:

In interface builder, I have a navigation controller with a custom subcontroller. The class name of this was set correctly, however the NIB name (select subcontroller, go to Attributes Inspector) was set to the wrong file (basically to one of a different target). Resetting this to the correct filename solved the issue.

Chopping answered 21/6, 2010 at 19:57 Comment(0)
N
0

I encounter the same error log when dealing with my tableview cell. I found that my UILabels have duplicated referencing outlets(you could check it out in the reference inspector) to both the file's owner and my cell's class. Things get well when I delete the reference to the file's owner.

Noctambulous answered 21/6, 2010 at 19:57 Comment(0)
S
0

I remember having a similar problem in the past, I solved it by changing the line:

_vicMain = [[UIViewController alloc] initWithNibName:@"vicMainScreen" bundle:nil];

into:

#include "vicLogin_iPad.h"       // This is the H file of the class holding the code for
                                 // processing all the IBOUtlets for the Login screen
.
.
.

_vicMain = [[vicLogin_iPad alloc] initWithNibName:@"vicMainScreen" bundle:nil];

Notice that I was initially declaring UIViewController to init my _vicMain, after using a pop-up window on top, I realised that both are using the same UIViewController.

By:

1) INCLUDing your class (of the sub-view), along with the same module that is doing the above _vicMain (which is a view controller object/variable) i.e. it's "vicLogin_iPad.h" in my case , and:

2) Use the your custom constructor to declare the object (i.e. instead of "xxx = [UIViewController alloc] ... ", you use "xxx = [vicLogin_iPad alloc] ... " instead.

the problem is resolved.

I hope this helps as it was a pain to pinpoint with the lack of details from the error message...

Regards Heider Sati

Spreader answered 21/6, 2010 at 19:57 Comment(0)
E
0

I found another possibility that may cause the issue.

When using "initWithNibName" method with the wrong xib name, it will lead to this kind of crash too.

Such as you choose to change a xib file's name, and then foget to change the name used in "initWithNibName" method to the same name.

Emergence answered 21/6, 2010 at 19:57 Comment(0)
S
0

This problem also happens if you want to design a small subview in a separate XIB file in Interface Builder, and in IB you set it to the same class as the parent view.

If you then show it like this:

UIViewController *vc = [[UIViewController alloc] initWithNibName:@"NameOfTheSubviewNibFile" bundle:nil];
[self.view addSubview:vc.view];

The view will appear, but if it's got IBOutlets connected to its File Owner, you'll get the error message. So, this should work instead:

  1. In your the parent view's code, declare an IBOutlet UIView *mySubview to reference the view in the subview's nib file
  2. In the subview's nib file, connect the File Owner to the view, and set it to mySubview
  3. show it by doing:
[[NSBundle mainBundle] loadNibNamed:@"NameOfTheSubviewNibFile" owner:self options:nil]
[self.view addSubview:mySubview];

and you will be fine!

Shoshonean answered 21/6, 2010 at 19:57 Comment(0)
R
0

Usually when this happens to me, @TechZen's answer does the trick. Yesterday, however, I spent an embarrassingly long time mucking with storyboard connections only to discover that the problem was in my code.

I have a custom view controller that handles various layouts in my storyboard, but one of the layouts needed a special label not used by the others. So I created a subclass like so:

@interface MyViewControllerSubclass : MyViewController

Then I added a private property in MyViewControllerSubclass.m:

@interface MyViewController ()
@property (weak, nonatomic) IBOutlet UILabel *crashesApp;
@end

Xcode happily allowed me to connect this IBOutlet, yet every time the view would load, the app would crash with the old "not key-value compliant for the key 'chrashesApp'".

The solution, which is semi-obvious in retrospect, was to change the private category to use the correct name, i.e., that of the subclass:

@interface MyViewControllerSubclass ()
@property (weak, nonatomic) IBOutlet UILabel *noMoreCrashing;
@end
Rhapsodic answered 21/6, 2010 at 19:57 Comment(0)
C
-1

In my case the View was UIView but the XIB Connection was to an IBOutlet of type LottieAnimationView. The actual lottie was a child of the UIView.

Connaught answered 21/6, 2010 at 19:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.