简体   繁体   English

Xcode - 如何修复“NSUnknownKeyException”,原因:……这个 class 与键 X 的键值编码不兼容”错误?

[英]Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error?

I'm trying to link a UILabel with an IBOutlet created in my class.我正在尝试将UILabel与在我的 class 中创建的IBOutlet链接起来。

My application is crashing with the following error.我的应用程序因以下错误而崩溃。

What does this mean?这是什么意思?

How can I fix it?我该如何解决?

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x6e36ae0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key XXX.' *** 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[<UIViewController 0x6e36ae0> setValue:forUndefinedKey:]:此 class 与键 XXX 的键值编码不兼容。”

You may have a bad connection in your xib.您的 xib 中可能连接不良。<\/h2>

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<\/strong> in your .h\/.m which you've already connected up to File's Owner in the nib.虽然 TechZen 的回答在这种情况下是绝对正确的,但另一个常见原因是当您更改 .h\/.m 中的 IBOutlet 属性的名称时<\/strong>,您已经连接到 nib 中的 File's Owner。

From your nib:从你的笔尖:

  1. Select the object in IB and go to the 'Connections Inspector'.在 IB 中选择对象并转到“连接检查器”。<\/li>
  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<\/strong> and build again.在“引用插座”下,确保您的对象仍未连接到旧属性名称...如果是,请单击小“x”以删除引用<\/strong>并重新构建。

    在此处输入图像描述<\/a>

    <\/li><\/ol>

    Another common cause if you are using Storyboard, your UIButton might have more then one assignings (Solution is almost the same as for nib):如果您使用 Storyboard,另一个常见原因是,您的 UIButton 可能有多个分配(解决方案与 nib 几乎相同):

    1. Open your storyboard and right click the UIButton打开故事板并右键单击 UIButton<\/li>
    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":删除带有小“x”的“主...”灰色窗口之一:

      示例 2<\/a>

      <\/li><\/ol>"

Your view controller may have the wrong class in your xib.您的视图控制器可能在您的 xib 中有错误的类。<\/h2>

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.' 'NSUnknownKeyException',原因:'[<UIViewController 0x3927310> setValue:forUndefinedKey:]:这个类不符合键字符串的键值编码。

<\/blockquote>

It is caused by the Second<\/code> view controller in MainWindow.xib<\/code> having a class of UIViewController<\/code> instead of SecondView<\/code><\/strong> .这是由MainWindow.xib<\/code>中的Second<\/code>视图控制器具有UIViewController<\/code>类而不是SecondView<\/code>的<\/strong>。 Changing to the correct class resolves the problem.更改为正确的类可以解决问题。

By the way, it is bad practice to have names like "string" in Objective-C.顺便说一句,在 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.此错误的另一个可能原因是:当将元素从一个控制器复制并粘贴到另一个控制器时,Xcode 会以某种方式保持与原始控制器的链接,即使在将此元素编辑并重新链接到新控制器之后也是如此。

Another possible reason for this error:<\/strong>此错误的另一个可能原因:<\/strong>

Bad Outlet.坏出口。

You have either removed<\/em> or renamed<\/em> an outlet name in your .h<\/code> file.您已在.h<\/code>文件中删除<\/em>或重命名<\/em>了出口名称。

Remove it in .xib<\/code> or .storyboard<\/code> file's Connection Inspector..xib<\/code>或.storyboard<\/code>文件的连接检查器中删除它。

One more possible reason<\/strong>还有一个可能的原因<\/strong>

(In my case) Extension of UIView with bindable properties and setting values for those bindable properties (ie shadow, corner radius etc.) then remove those properties from UIView extension (for some reason) but the following <userDefinedRuntimeAttributes><\/code> remained in xml (of foo.storyboard<\/code> ): (在我的情况下)具有可绑定属性的 UIView 扩展并为这些可绑定属性(即阴影、角半径等)设置值然后从 UIView 扩展中删除这些属性(出于某种原因)但以下<userDefinedRuntimeAttributes><\/code>保留在 xml 中( foo.storyboard<\/code> ):

 <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><\/code><\/pre>

Solution:<\/strong> Right click on foo.storyboard<\/code> > Open as Source Code > search by keyPath (ie shadowRadius) > Delete the <\/userDefinedRuntimeAttributes><\/code> that causing the problem解决方法:<\/strong>右键foo.storyboard<\/code> > Open as Source Code > search by keyPath (ie shadowRadius) > 删除导致问题的<\/userDefinedRuntimeAttributes><\/code>

"

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.如果您有多个目标,请选择所需的目标。

在此处输入图像描述<\/a>

"

I had this error when I was trying to implement a custom ViewCell for a table.当我尝试为表实现自定义 ViewCell 时出现此错误。 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.当我突出显示 XIB 的视图控制器并连接到 CellView 中的元素时,一旦我删除了这些错误,就会导致错误“此类与键的键值编码不兼容”。

Delete the connections in the below image.删除下图中的连接。 突出显示文件所有者时删除检查器中的连接

Just make sure that you only have the connections with the Table View Cell.只需确保您仅与 Table View Cell 建立连接。 To check click on table view cell and in INSPECTOR look for your connections.要检查单击表格视图单元格并在 INSPECTOR 中查找您的连接。

当突出显示 Table View Cell 时,连接应该在此处

我不得不从模拟器/iPhone 中删除该应用程序以消除此错误。

If it is an iPhone only app, not a universal one, make sure the following field is empty:如果它是 iPhone 专用应用程序,而不是通用应用程序,请确保以下字段为空:

Targets > Summary > iPhone\/iPod Deployment Info > Main Interface目标 > 摘要 > iPhone\/iPod 部署信息 > 主界面

If you specify an xib there it crashes.如果你在那里指定一个xib,它会崩溃。

"

This error indicates that an already connected Interface Builder object is removed/renamed in its owner's source (File's Owner).此错误表示已连接的 Interface Builder对象在其所有者的源(文件的所有者)中被删除/重命名

Control-click on the Files's Owner in the Interface Builder if you see a exclamation mark you need to fix that.如果您看到需要修复的感叹号,请按住 Control 并单击 Interface Builder 中的文件所有者

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.在下图中,您可以看到“aRemovedView”的右侧有一个感叹号,这是因为我删除了 IBOutlet 视图对象,而它已经在 IB 中连接。

在此处输入图像描述

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.'这会出现以下错误:由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类与键 aRemovedView 的键值编码不兼容。”

I had the same problem and while TechZen's answer may indeed be amazing I found it hard to apply to my situation.我遇到了同样的问题,虽然 TechZen 的回答可能确实令人惊叹,但我发现它很难适用于我的情况。

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 .最终,我通过Objects下列出的 Controller(在下图中突出显示)而不是通过File Owner链接标签来解决问题。

Hope this helps.希望这可以帮助。

在此处输入图像描述

in my case it was an error in the storyboard source code, follow these steps:就我而言,这是情节提要源代码中的错误,请按照下列步骤操作:

  1. first open your story board as source code首先打开你的故事板作为源代码<\/li>
  2. search for <connections><\/code>搜索<connections><\/code><\/li>
  3. remove unwanted connections删除不需要的连接<\/li><\/ol>

    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><\/code><\/pre>

    As you see, these are connections between your code variables' names and the storyboard layout xml tags ;)如您所见,这些是您的代码变量名称和情节提要布局 xml 标记之间的联系;)

    "

在此处输入图像描述在此处输入图像描述

My fix was similar to Gerard Grundy's.我的修复与 Gerard Grundy 的类似。 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.在使用 XIB 创建自定义 UITableViewCell 时,我错误地将自定义类名称应用于文件所有者而不是 UITableViewCell。 Applying the class to the UITableViewCell on the canvas and connecting my IBOutlet properties to it solved the issue.将类应用到画布上的 UITableViewCell 并将我的 IBOutlet 属性连接到它解决了这个问题。

  1. You only need to specify IBOutlet<\/code> once, the IBOutlet<\/code> label your ivar is unnecessary.您只需要指定一次IBOutlet<\/code> ,您的 ivar 的IBOutlet<\/code>标签是不必要的。<\/li>
  2. Are you instantiating your NIB using your UIViewController<\/code> ?您是否使用UIViewController<\/code>实例化您的 NIB? At some point you should be calling [SecondView initWithNibName:@"yourNibName" bundle:nil];<\/code>在某些时候,您应该调用[SecondView initWithNibName:@"yourNibName" bundle:nil];<\/code><\/li><\/ol>"

This was happening to me only when debugging on a device (iPhone).只有在设备(iPhone)上调试时才会发生这种情况。 The iOS Simulator was working OK. iOS 模拟器工作正常。 Doing a "Product->Clean" from Xcode seemed to solve the problem, but I have no idea why.从 Xcode 执行“Product->Clean”似乎可以解决问题,但我不知道为什么。

I had exact same error message and thanks (!!) to Kira from http://www.idev101.com I was able to solve the challenge.我收到了完全相同的错误消息,并感谢(!!)来自http://www.idev101.com的 Kira,我能够解决这个挑战。 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.我现在在这里发布下一个关于 StackOverFlow 的帖子,并且遇到了与我相同的挑战,因为那个人很可能会通过 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 eg another UIViewController.在您要调用的实现(.m 文件)中,例如另一个 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.如果我只是为像我这样的初学者说明显而易见的事情并且可能会因为这与问题不完全相关而可能会被否决,我绝对不会感到抱歉,但我现在正在搜索 4 (?!?) 小时来寻找这些错误消息的答案. If I can spare this to 1 or 2 people that'd be great :)如果我能把这个留给 1 或 2 个人那就太好了:)

PS: For those interested in how the code continues for loading the other UIViewController: PS:对于那些对代码如何继续加载另一个 UIViewController 感兴趣的人:

    [self presentViewController:deviceViewController animated:YES completion:nil];

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如果你

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.即使您删除了代码,或者即使您已经制作了足够的 cmd+Z,您也需要进入情节提要的连接检查器,查看您创建的操作或插座是否仍然存在。

"

This happens to me when my view controller originally had an .xib file, but now is created programmatically.当我的视图控制器最初有一个 .xib 文件但现在以编程方式创建时,我就会发生这种情况。

Even though I have deleted the .xib file from this project.即使我已经从这个项目中删除了 .xib 文件。 The users iPhone/iPad may contain an .xib files for this viewcontroller.用户 iPhone/iPad 可能包含此视图控制器的 .xib 文件。

Attempting to load an .xib file usually causes this crash:尝试加载 .xib 文件通常会导致此崩溃:

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];
}

"Module" property of View Controller in the Identity Inspector might be different than what you expected. Identity Inspector 中视图控制器的“模块”属性可能与您的预期不同。 Also make sure that new classes are added to your target list.还要确保将新类添加到您的目标列表中。

"

I had a similar problem for a project that has two targets (with their own MainWindow XIB).对于具有两个目标(具有自己的 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.对我来说导致此错误的根本问题是 UIViewController 类未包含在第二个项目的资源列表中。 Ie interface builder allowed me to specify it in MainWindow.xib, but at runtime the system couldn't locate the class.即界面生成器允许我在 MainWindow.xib 中指定它,但在运行时系统无法找到该类。

Ie cmd-click on the UIViewController class in question and double-check that it's included in the 'Targets' tab.即在有问题的 UIViewController 类上单击 cmd 并仔细检查它是否包含在“目标”选项卡中。

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.浏览所有这些答案似乎最适用于使用 UI 和故事板的东西。 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.我知道原始海报似乎确实在使用 UI,但是在搜索此错误的可能原因时,大多数问题都会回到这个问题,而其他问题则作为重复项被关闭,或者只是在故事板中连接事物时遇到问题,所以我会添加我的解决方案。

I was working on coding a web service in Swift 2. I had built all the needed proxy objects and stubs.我正在编写 Swift 2 中的 Web 服务。我已经构建了所有需要的代理对象和存根。 As I looped through the returned XML I was dynamically instantiating my objects, which all came from NSObject and using setValue:forKey on them.当我遍历返回的 XML 时,我正在动态地实例化我的对象,这些对象都来自NSObject并在它们上使用setValue:forKey Every time setValue:forKey tried to set a property it blew up with this error.每次setValue:forKey尝试设置一个属性时,都会出现此错误。

I had a switch statement for each type I was dealing with (eg 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 .对于我正在处理的每种类型(例如Bool?CShort?String? ),我都有一个 switch 语句,并且对于每个 XML 节点,我检查了对象上的类型,然后将值转换为该类型并尝试用setValue:forKey设置它。

Eventually I started commenting out all these setValue:forKey lines and found that my default switch statement case did work for String?最终,我开始注释掉所有这些setValue:forKey行,发现我的default switch 语句案例确实适用于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?我终于发现你不能使用带有setValue:forKey的可选 swift 类型,除非它们直接映射到像String? or NSNumber?还是NSNumber? . . I ended up changing all CShort?我最终改变了所有CShort? types to NSNumber?类型为NSNumber? since that has a direct mapping.因为它具有直接映射。 For Bool?对于Bool? in my case it was fine for me to just use Bool and initialize it to false .就我而言,我只需使用Bool并将其初始化为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!!".无论如何,多么令人头疼,希望这可以帮助遇到类似问题并不断被重定向到这个问题并自言自语的其他人,“我没有在 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.您不能在 Optional Int 属性上使用 KVC,因为 KVC 是 Cocoa / Objective-C,而 Objective-C 看不到 Optional Int - 它没有桥接到 Objective-C。 Objective-C can only see types that are bridged to Objective-C: Objective-C 只能看到桥接到 Objective-C 的类型:

class types that are derived from NSObject从 NSObject 派生的类类型

class types that are exposed with @objc使用@objc 公开的类类型

Swift structs that are bridged桥接的 Swift 结构

"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我没有找到像上面这样的任何答案,所以它可能可以帮助有同样问题的人

That might be the case of referencing a component from Xib Interface that you have renamed or delete.这可能是从您已重命名或删除的 Xib 接口中引用组件的情况。 Re-referencing works for me.重新引用对我有用。

"

I just had this issue in my duplicated project and solved by checking 2 places:我刚刚在我的重复项目中遇到了这个问题,并通过检查 2 个地方来解决:

1- Make sure you have the .m file in the list -> Project - Build Phases - Compile Sources 1-确保列表中有.m文件->项目-构建阶段-编译源
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. 2- 之后,转到界面生成器(可能这是仅 IB 发生的错误)并取消链接所有属性、标签、图像等......然后重新链接所有。 I have realized that I've removed an attribute but it was still linked in IB.我意识到我已经删除了一个属性,但它仍然在 IB 中链接。

Hope it works for some.希望它适用于某些人。

This error is something else!这个错误是另外一回事!

Here is how i Fixed it.这是我修复它的方法。 I'm using xcode Version 6.1.1 and using swift.我正在使用 xcode 版本 6.1.1 并使用 swift。 I got this error every time my app tried to perform a segue to jump to the next screen.每次我的应用程序尝试执行 segue 以跳转到下一个屏幕时,我都会收到此错误。 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.检查日志并确保 NEXT SCREEN 中的所有按钮都具有正确的操作,如果有任何 segue,请确保它们具有唯一标识符。 (This was the problem) (这是问题)
    • One of the segues did not have a unique identifier其中一个 segue 没有唯一标识符
    • 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,干杯,

In my case.就我而言。 I didn't have missing outlets in xib-files after merging.合并后,我没有在 xib 文件中丢失出口。

Shift + Command + K Shift + Command + K

<\/blockquote>

solved my problem.解决了我的问题。 I cleaned my project and rebuilt.我清理了我的项目并重建了。

"

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. Interface Builder 仍然看到键并让我连接它们,但在运行时它使用的是没有新键的类的另一个副本。

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).为了找到哪个是“正确的”副本,我使用 XCode 的 cmd-单击其他地方的类名以跳转到正确的副本,然后我删除了未使用的坏副本(首先从未使用的副本中带来我的编辑)。

Moral of the story: duplicate class files are bad.故事的寓意:重复的类文件是不好的。

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.突出显示您的 .m 文件。
  2. In the right pane, select the File Inspector.在右窗格中,选择文件检查器。
  3. Under the "Target Membership" section, make sure the appropriate build target is checked.在“Target Membership”部分下,确保选中了适当的构建目标。

Hope this helps somebody out there.希望这可以帮助那里的人。

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如果您有一个带有导致问题的 IBOutlets 的自定义 UIViewController 子类,那么我发现真正摆脱错误的唯一步骤是

.1 Change the class to UIViewController .1 将类更改为 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). .2 断开所有插座(它们现在都将带有黄色警告三角形)- 断开有问题的插座可能就足够了。

.3 Do all the standard steps - ↑⌘K, delete Derived Data (, prayer mats, worry beads) .3 执行所有标准步骤 - ↑⌘K,删除派生数据(祈祷垫,忧虑珠)

.4 Launch the app - go to the problematic scene. .4 启动应用程序 - 转到有问题的场景。

.5 Kill the app, go back to Interface Builder change the class back to your custom class name. .5 终止应用程序,返回 Interface Builder 将类更改回您的自定义类名称。

.6 Reconnect your outlets. .6 重新连接您的插座。

Launch the app & this will normally have cleared up the key-value compliance issues.启动应用程序,这通常会清除键值合规性问题。

就我而言,这是由于引用了错误的 Nib 造成的:

BMTester *viewController = [[BMTester alloc] initWithNibName:@"WrongNibName" bundle:nil];

I had the same kind of problem.我有同样的问题。 I created a tableviewCell in a XIB file and was getting that kind of error.我在 XIB 文件中创建了一个 tableviewCell 并遇到了这种错误。 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).我只是把它拿出来并设置单元格的类(在 xib 文件上单击单元格的边框,转到右侧面板上的第三个选项卡,它说类选择了您的视图控制器)。

Also try cleaning your code.也尝试清理你的代码。

You may have outlets to UI Element but not IBOutlet property in .h File您可能有 UI 元素的出口,但 .h 文件中没有 IBOutlet 属性

For all UI element in Connection Attribute check outlets and it corresponding property in .h header file.对于 Connection Attribute 中的所有 UI 元素,请检查 outlets 及其 .h 头文件中的相应属性。

May be missing one or more property entry in .h file. .h 文件中可能缺少一个或多个属性条目。

In my case it was the module that was specified to the wrong target .在我的情况下,它是指定给错误targetmodule Simply deleting the module name and checking Inherit Module from target did the trick.只需删除module名称并检查Inherit Module from target就可以了。

在此处输入图像描述

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.上述解决方案似乎不是问题,所以我最终删除了视图控制器并将其重新添加(当然还重新连接了 segue 并重新分配了类),从而修复了它。 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.我不知道它到底是什么,但在这开始前不久我已经重命名了关联的视图控制器类,所以也许这已经解决了一些问题。

"

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.我的代码如何变得正常并开始工作。

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).通过在 Storyboard/xib 界面中选择有问题的对象并打开 Connections Inspector(View->Utilities->Show Connections Inspector)来检查您是否有杂散的引用插座。 If you do remove the unwanted connections and you should be good to go.如果您确实删除了不需要的连接,那么您应该一切顺利。

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.我发现 nib 文件仍然有对它的引用。 I deleted the block that referenced it and everything was fixed.我删除了引用它的块,一切都已修复。

In Project Navigator,在项目导航器中,

Find the Nib (xib) file.找到 Nib (xib) 文件。 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>

当视图控制器类中的两个变量引用 UI 标签或其他 UI 元素并且我删除了其中一个变量时,我也会发生这种情况。

我有同样的问题。这发生在我的项目中,因为我更改了产品名称,但在界面生成器中,我的旧名称为 Module,这会导致崩溃,因此请务必检查所有 xib 模块名称是否也已更改。

您可能需要删除 outlet ,通过将表单 IB 绘制到 .H 文件来重新创建它。

In my case it was that an IBOutlet's property name in a ViewController.m was changed, but the one in Storyboard was not.在我的情况下,ViewController.m 中的 IBOutlet 属性名称已更改,但 Storyboard 中的属性名称未更改。 Reintroducing the IBOutlet into the ViewController.m per ctrl-drag solved the problem.通过 ctrl-drag 将 IBOutlet 重新引入 ViewController.m 解决了这个问题。 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.我还注意到一种在 XCode 中找到这种“孤立”IBOutlets 的方法:(看图片)那些不是“孤立”的有同心圆而不是行号。

“孤立”IBOutlets 在行号列中没有同心圆。

I resolved this problem by doing 2 things:我通过做两件事解决了这个问题:

  1. Fixed Class reference of the view:视图的固定类引用:

  1. Reimported all Outlets:重新导入所有奥特莱斯:

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.我已重命名 mainstoryboard.storyboard,但没有重置部署信息。

这种情况的另一个原因是您将该属性声明为@dynamic,但类在父类中找不到它。

In my case,就我而言,

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

was the reason.是原因。

replacing this with initWithNibName , resolved.initWithNibName替换它,解决。

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)解决方案是重新制作整个故事板,因为我从另一个故事板复制它(因为它几乎相同)

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 .有时没有从目标添加或删除 swift 文件,请转到目标--> 构建设置--> 编译源--> 查看是否缺少任何所需的 swift 类文件。 In my case Application was crashing due to swift source file not present in compile.在我的情况下,由于编译中不存在 swift 源文件,应用程序崩溃了。

I had this problem with swift classes after upgrading to xcode7.升级到 xcode7 后,我遇到了 swift 类的问题。 Solved it by using the @objc directive:通过使用@objc 指令解决了这个问题:

@objc(XXXViewController) class XXXViewController @objc(XXXViewController) 类 XXXViewController

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 ie check the is initial View Controller on which ever view controller you like.您只需要添加情节提要的入口点,即检查您喜欢哪个视图控制器的is initial View Controller Otherwise it will be a gray scene and throw you an error.否则它将是一个灰色的场景并给你一个错误。

在此处输入图像描述

I had this happen when i had a UIView linked into a storyboard and connected IBOutlet like:当我将 UIView 链接到故事板并连接 IBOutlet 时,我发生了这种情况:

@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.但后来,我将 UIView 变成了一个自定义类,但忘记更改上面定义的这个 IBOutlet 的类名。 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.这是一个奇怪的错误,因为如果自定义视图没有子视图,它不会抱怨,但是一旦有子视图,它就会显示问题中所述的错误,但是在其中一个子视图上而不是在实际存在问题的外部 UIView 上。 had me deleting and readding all the subviews trying to find the problem, when in fact had nothing to do with the subviews让我删除并阅读所有试图找到问题的子视图,而实际上与子视图无关

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.我想如果您使用故事板作为启动屏幕文件,它不应该连接到视图控制器,因为它还没有被加载。

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.我想如果您使用故事板作为启动屏幕文件,它不应该连接到视图控制器,因为它还没有被加载。

It could mean you're trying to use a sort descriptor without an atsign at the beginning.这可能意味着您正在尝试使用开头没有 atsign 的排序描述符。 As in:如:

[array valueForKeyPath:@"distinctUnionOfObjects.self"]

Which must actually be:实际上必须是:

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

I had the same issue, and the cause was due to specifying a Module in Interface Builder (as opposed to leaving it blank).我遇到了同样的问题,原因是在 Interface Builder 中指定了一个模块(而不是将其留空)。 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!因此,当我使用与我设置的模块不同的模块时,应用程序会崩溃:S ...希望这对其他人有帮助,因为我的问题不是由于插座损坏或过时!

I had this problem with storyboard and swift class for ui view controller.我在故事板和 ui 视图控制器的 swift 类中遇到了这个问题。 Solved it by using the @objc directive:通过使用@objc 指令解决了这个问题:

@objc(MyViewController) class MyViewController

My problem started after i changed the Target name.在我更改目标名称后,我的问题就开始了。

My own custom UI classes had the Module name set to the old target name.我自己的自定义 UI 类将模块名称设置为旧目标名称。

I changed the target name to the new one and it works fine now.我将目标名称更改为新名称,现在可以正常工作。

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 eg 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.然后添加一个 IBOutlet,无法引用 IBOutlet 并且应用程序将崩溃并出现上述错误。

Fix: Assign an owner for the view.修复:为视图分配所有者。

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

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.插座都正确连接到情节提要,并且在原型单元的身份检查器中正确命名了 Class 字段。

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.最后的工作是将故事板身份检查器中的类更改为默认的 UITableViewCell,按 Enter,然后将其更改回我的自定义类的名称。 For some reason, this worked.出于某种原因,这行得通。

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.在“connections”标签中查找“outlet”标签,其中“property”属性设置为您在异常中获得的名称。
  5. Remove that outlet tag.删除该插座标签。
  6. Hit "Command + B", Enjoy!点击“Command + B”,享受吧!

Usually when this happens to me, @TechZen's answer does the trick.通常当这种情况发生在我身上时,@TechZen 的回答就可以解决问题。 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:然后我在 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'". Xcode 很高兴地允许我连接这个 IBOutlet,但每次加载视图时,应用程序都会因旧的“不符合键 'chrashesApp' 的键值”而崩溃。

The solution, which is semi-obvious in retrospect, was to change the private category to use the correct name, ie, that of the subclass :回想起来半明显的解决方案是更改私有类别以使用正确的名称,即子类的名称

@interface MyViewControllerSubclass ()
@property (weak, nonatomic) IBOutlet UILabel *noMoreCrashing;
@end

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.如果您想在 Interface Builder 中的单独 XIB 文件中设计一个小的子视图,并且在 IB 中将其设置为与父视图相同的类,也会发生此问题。

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.该视图将出现,但如果它的IBOutlets连接到其文件所有者,您将收到错误消息。 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在父视图的代码中,声明一个IBOutlet UIView *mySubview以引用子视图的 nib 文件中的视图
  2. In the subview's nib file, connect the File Owner to the view, and set it to mySubview在子视图的 nib 文件中,将 File Owner 连接到视图,并将其设置为mySubview
  3. show it by doing:通过这样做来展示它:
[[NSBundle mainBundle] loadNibNamed:@"NameOfTheSubviewNibFile" owner:self options:nil]
[self.view addSubview:mySubview];

and you will be fine!你会没事的!

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.当使用带有错误xib名称的“initWithNibName”方法时,也会导致这种崩溃。

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.比如你选择改变一个xib文件的名字,然后foget把“initWithNibName”方法中使用的名字改成相同的名字。

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.请注意,我最初声明 UIViewController 来初始化我的 _vicMain,在使用顶部的弹出窗口后,我意识到两者都使用相同的 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) ie it's "vicLogin_iPad.h" in my case , and: 1)包括您的类(子视图),以及执行上述_vicMain(这是一个视图控制器对象/变量)的相同模块,即在我的情况下它是“vicLogin_iPad.h”,并且:

2) Use the your custom constructor to declare the object (ie instead of " xxx = [UIViewController alloc] ... ", you use " xxx = [vicLogin_iPad alloc] ... " instead. 2)使用您的自定义构造函数来声明对象(即,而不是“ xxx = [UIViewController alloc] ... ”,而是使用“ xxx = [vicLogin_iPad alloc] ... ”。

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问候海德·萨蒂

I encounter the same error log when dealing with my tableview cell.在处理我的 tableview 单元格时,我遇到了相同的错误日志。 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.我发现我的 UILabel 已将引用出口(您可以在引用检查器中检查出来)复制到文件的所有者和我的单元格的类。 Things get well when I delete the reference to the file's owner.当我删除对文件所有者的引用时,情况会好转。

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).其类名设置正确,但是 NIB 名称(选择子控制器,转到 Attributes Inspector)设置为错误文件(基本上设置为不同目标之一)。 Resetting this to the correct filename solved the issue.将其重置为正确的文件名解决了这个问题。

I had this problem too.我也有这个问题。 I had copied a view with an IBOutlet from one xib file to another xib file.我已将带有 IBOutlet 的视图从一个 xib 文件复制到另一个 xib 文件。 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.我最终重新启动了 xcode 来解决这个问题。

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在 IB 中,将 ViewController 添加到情节提要,删除其视图并将自定义类设置为“MyViewController”,以便从 MyViewController.xib 实例化视图

Specifying Storyboard ID the same "MyViewController" causes exception.将 Storyboard ID 指定为相同的“MyViewController”会导致异常。

Changing Storyboard ID to some different name resolves the issue.将 Storyboard ID 更改为其他名称可以解决此问题。

Did you leave your picker object unconnected?您是否让您的选择器对象处于未连接状态?

lol 54 answers and not one of them is my solution.大声笑 54 个答案,其中没有一个是我的解决方案。 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.就我而言,这是因为我的 VC 上有一个选择器对象,但没有为它设置出口和操作。

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.但似乎你不能为选择器做到这一点。

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.这发生在我身上只是因为我正在观察文本字段的“文本”属性,而我应该观察“文本”属性。

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.我的麻烦的原因是我复制了一个故事板文件(如果我没记错的话,在 Xcode 之外),然后复制文件中的所有视图控制器都具有与原始文件中相同的对象 ID。 The remedy is to copy-pasted the view controllers, and they will then get a new object-ID.补救措施是复制粘贴视图控制器,然后它们将获得一个新的对象 ID。 You can see the object-ID in the Identity Inspector.您可以在 Identity Inspector 中看到对象 ID。

Make sure you add the custom class' (even empty) implementation in the .m file like:确保在.m文件中添加自定义类(甚至是空的)实现,例如:

@implementation MySubclass
@end

In my case, I had added a ViewController to the storyboard, but I didn't assign it a Storyboard ID in the designer.在我的例子中,我已经向情节提要添加了一个 ViewController,但我没有在设计器中为其分配情节提要 ID。 Once I gave it an ID, it worked.一旦我给它一个ID,它就起作用了。

using Xamarin/Visual Studio 2015.使用 Xamarin/Visual Studio 2015。

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.我的项目中有另一个子模块,我在主模块中命名了一个与另一个类同名的新类,我的新类没有 xib 文件(100%按代码),但主模块中的另一个类有 xib 文件。 I think Xcode linked wrong the new class with the xib file in main module.我认为 Xcode 将新类与主模块中的 xib 文件链接错误。

That the reason for crash with message:消息崩溃的原因:

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

To add to this epic saga of a thread...为了添加到这个史诗般的线程传奇......

My view controller had an attribution above it: @objc(TheNameOfMyViewController)我的视图控制器上面有一个属性:@objc(TheNameOfMyViewController)

This made all the Outlets crash with "not key value compliant" error for each Outlet.这使得所有 Outlets 崩溃,每个 Outlet 出现“不符合键值”错误。 This was only an issue on IOS12 and below.这只是 IOS12 及以下版本的问题。 It worked fine on iOS 13.它在 iOS 13 上运行良好。

Removing that modifier fixed this problem.删除该修饰符解决了这个问题。 All the outlets are working fine now.现在所有的网点都工作正常。

I am using the Xamarin.IOS to create the custom nib.我正在使用 Xamarin.IOS 创建自定义笔尖。 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.最后我找到了根本原因,转到 Xcode 并选择了 nib 文件,在 Interface Builder 中,选择 UIView 类并选择 Connections Inspector 并删除默认插座,如下所示。 在此处输入图像描述

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.唯一为我修复它的是更改我的自定义视图 xib 文件的名称。

My custom view and xib had the same name.我的自定义视图和 xib 具有相同的名称。 Renaming the xib fixed it.重命名 xib 修复它。

NSUnknownKeyException error NSUnknownKeyException 错误

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

I got this error when .xib file(eg TableViewCell.xib) had the same name as cell class(eg TableViewCell.swift).xib文件(例如 TableViewCell.xib)与单元格类(例如 TableViewCell.swift)具有相同的名称时,我收到此错误

The correct approach is:正确的做法是:

TableViewCell.swift -> View.swift <-> View.xib

For me it, I had to click the file's Owner object and navigate to connections and removed the problematic connections对我来说,我必须单击文件的所有者 object 并导航到连接并删除有问题的连接

Thread 1: "[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key xxx."线程 1:“[setValue:forUndefinedKey:]:此 class 不符合键 xxx 的键值编码。”

You can get this error when:在以下情况下会出现此错误:

  1. .xib + UITableViewHeaderFooterView .xib + UITableViewHeaderFooterView

When you work with UITableView where show heade/footer which extends UITableViewHeaderFooterView and connect with .swift file and当您使用UITableView ,显示扩展UITableViewHeaderFooterView的页眉/页脚并与.swift文件和

  • set File's Owner设置File's Owner

correct way:正确方法:

  • set Custom Class for containerView instead改为为containerView设置Custom Class

在此处输入图像描述

Remove button reference by clicking the button and then re-create reference to this button.通过单击按钮删除按钮引用,然后重新创建对此按钮的引用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “&#39;NSUnknownKeyException&#39;,原因:…此类与键scoreArray的键值编码不兼容” - “'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key scoreArray ” 解决“&#39;NSUnknownKeyException&#39;,原因:此类不是密钥值编码兼容的密钥X”异常 - Resolve "'NSUnknownKeyException', reason:This class is not key value coding-compliant for the key X” exception 收到“ NSUnknownKeyException错误”,原因:setValue:forUndefinedKey:此类不符合键值编码的键说明 - getting the error of NSUnknownKeyException', reason: setValue:forUndefinedKey: this class is not key value coding-compliant for the key description NSUnknownKeyException:此类与键的键值编码不兼容 - NSUnknownKeyException: this class is not key value coding-compliant for the key Xamarin.iOS NSUnknownKeyException 原因:[setValue:forUndefinedKey:]:此类不是键 staticDataSource 的键值编码兼容 - Xamarin.iOS NSUnknownKeyException Reason: [ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key staticDataSource Xcode 8错误:此类与键敌人TITLELabel的键值编码不兼容 - Xcode 8 error: this class is not key value coding-compliant for the key enemyTitleLabel 这个 class 不是键值编码兼容错误? Xcode 11 - this class is not key value coding-compliant error? Xcode 11 Xcode“这个类不是密钥值编码兼容的关键页面控件。” - Xcode “this class is not key value coding-compliant for the key pageControl.” Xcode Swift-此类与密钥uri的密钥值编码不兼容 - Xcode Swift - This class is not key value coding-compliant for the key uri 未捕获的异常&#39;NSUnknownKeyException&#39;-此类与键button的键值编码不兼容 - uncaught exception 'NSUnknownKeyException' - this class is not key value coding-compliant for the key buttonPressed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM