2013-02-18 146 views
8
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
    UIViewController* vc = [sb instantiateViewControllerWithIdentifier:@"SettingsViewController"]; 
    [[self navigationController] pushViewController:vc animated:YES]; 

尝试从Storyboard中的NavigationController推送ViewController,并且不断收到此错误。错误:此类不是关键值编码兼容的密钥密钥路径

* 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

+0

相关:http://stackoverflow.com/questions/3088059/what-does-this-mean-nsunknownkeyexception-reason-this-class-is-not-key – jtbandes 2015-08-16 18:41:56

回答

1

使用此&检查:

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
SettingsViewController *myVC = (SettingsViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"SettingsViewController"]; 
[self.navigationController pushViewController:myVC animated:YES]; 
+2

这是更好的代码,但不会解决问题。将vc声明为通用视图控制器是可以接受的,只要您不打算调用SettingsViewController上定义的任何方法即可。 – danh 2013-02-18 04:30:16

4

最有可能的,在故事板中定义的SettingsViewController包含一个IBOutlet所谓的keyPath的引用,但的keyPath没有在类中定义。

要解决该问题,请选择故事板中的视图控制器,选择连接检查器(右侧窗格最右边的选项卡),然后查看连接。可能有一个叫keyPath,它可能有一个“!”靠近它。删除一个(和其他任何与“!”)。

41

我得到了这个错误,因为我在“身份检查器”选项卡的“用户定义的运行时属性”字段中放置了一些东西。在mystake中,我留下了Key Path列的默认keyPath值并导致了问题。

Screenshot from xcode interface builder

+0

非常好的观察。谢谢:) – staticVoidMan 2015-07-15 10:25:25

+0

你需要改变键路径(layer.circleRadius),它的类型(数字)和值(30)..例如假设你需要将square.circleRadius转换为circle,请输入:number和value is(身高/ 2或宽度/ 2) – 2015-08-31 07:58:39

+0

极好的答案.. – JAck 2016-11-02 09:27:07

0

右键XIB文件,源代码开放,以找到 “的keyPath”。

相关问题