xcode 错误:此类不符合键 keyPath 的键值编码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14929171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: This class is not key value coding-compliant for the key keyPath
提问by user2080841
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController* vc = [sb instantiateViewControllerWithIdentifier:@"SettingsViewController"];
[[self navigationController] pushViewController:vc animated:YES];
Trying to push a viewcontroller from my NavigationController in Storyboard and I keep getting this error.
尝试从 Storyboard 中的 NavigationController 推送视图控制器,但我不断收到此错误。
* Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<SettingsViewController 0x1f98f100> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key keyPath.' *First throw call stack: (0x31f4a3e7 0x39c3b963 0x31f4a0d5 0x327b87d9 0x327b4543 0x31ed08a5 0x33ef5e69 0x340e5b09 0x71aa3 0x33e1b31d 0x33e9dda9 0x32859657 0x31f1f857 0x31f1f503 0x31f1e177 0x31e9123d 0x31e910c9 0x35a6f33b 0x33dad2b9 0x6567d 0x3a068b20) libc++abi.dylib: terminate called throwing an exception
* 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[<SettingsViewController 0x1f98f100> setValue:forUndefinedKey:]: 此类与键 keyPath 的键值编码不兼容。” *第一掷调用堆栈:(0x31f4a3e7 0x39c3b963 0x31f4a0d5 0x327b87d9 0x327b4543 0x31ed08a5 0x33ef5e69 0x340e5b09 0x71aa3 0x33e1b31d 0x33e9dda9 0x32859657 0x31f1f857 0x31f1f503 0x31f1e177 0x31e9123d 0x31e910c9 0x35a6f33b 0x33dad2b9 0x6567d 0x3a068b20)的libc ++ abi.dylib:终止叫做抛出一个异常
回答by mameluc
I got this error becouse I had put something in the "User Defined Runtime Attributes" field in the "Identity inspector" tab. By mystake I left the default keyPath value for the Key Path column and that caused the problem.
我收到此错误是因为我在“身份检查器”选项卡的“用户定义的运行时属性”字段中放置了一些内容。由于我的原因,我为 Key Path 列保留了默认的 keyPath 值,这导致了问题。
回答by danh
Most likely, the SettingsViewController defined in the storyboard contains a reference to an IBOutlet called keyPath, but keyPath is not defined in the class.
最有可能的是,故事板中定义的 SettingsViewController 包含对名为 keyPath 的 IBOutlet 的引用,但 keyPath 未在类中定义。
To remedy, select the view controller in storyboard, select the connections inspector (far right tab on the right pane), and review the connections. There's probably one there called keyPath, and it probably has a "!" near it. Delete that one (and any others with "!").
要进行补救,请在故事板中选择视图控制器,选择连接检查器(右侧窗格中最右侧的选项卡),然后查看连接。那里可能有一个叫做 keyPath 的,它可能有一个“!” 靠近它。删除那个(以及任何其他带有“!”的)。
回答by Vishal
Use this & check:
使用这个并检查:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
SettingsViewController *myVC = (SettingsViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"SettingsViewController"];
[self.navigationController pushViewController:myVC animated:YES];
回答by user5158717
Right click xib file, open as source code to find the "keyPath".
右键单击xib文件,作为源代码打开找到“keyPath”。