此类不是密钥XXX的密钥值编码兼容

编程入门 行业动态 更新时间:2024-10-05 11:24:37
本文介绍了此类不是密钥XXX的密钥值编码兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是所有编程的初学者,并且一直试图从Big Nerd Ranch Books中实现一些自学的东西。但我真的被这个问题困扰了,是的,我已经在这个和其他论坛上搜索了可能的解决方案而没有成功。以下是代码:

I'm a beginner in everything programming and have been trying to implement some self learned stuff from the Big Nerd Ranch Books. But I'm really stumped by this problem, and yes, I have searched this and other forums for possible solutions with no success. Here is the code:

ANKYViewController.h:

ANKYViewController.h:

#import <UIKit/UIKit.h> @interface ANKYViewController : UIViewController @property (weak, nonatomic) IBOutlet UITextField *weightFieldDeadlift; @property (weak, nonatomic) IBOutlet UITextField *repFieldDeadlift; @property (strong, nonatomic) IBOutlet UILabel *workingOneRMDeadlift; @property (weak, nonatomic) IBOutlet UITextField *weightFieldBenchPress; @property (weak, nonatomic) IBOutlet UITextField *repFieldBenchPress; @property (strong, nonatomic) IBOutlet UILabel *workingOneRMBenchPress; @property (weak, nonatomic) IBOutlet UITextField *weightFieldSquat; @property (weak, nonatomic) IBOutlet UITextField *repFieldSquat; @property (strong, nonatomic) IBOutlet UILabel *workingOneRMSquat; @property (weak, nonatomic) IBOutlet UITextField *weightFieldMilitaryPress; @property (weak, nonatomic) IBOutlet UITextField *repFieldMilitaryPress; @property (strong, nonatomic) IBOutlet UILabel *workingOneRMMilitaryPress; - (IBAction)calculateOneRM:(id)sender; @end

ANKYViewController.m:

ANKYViewController.m:

#import "ANKYViewController.h" @interface ANKYViewController () @end @implementation ANKYViewController @synthesize weightFieldDeadlift; @synthesize repFieldBenchPress; @synthesize workingOneRMBenchPress; @synthesize weightFieldSquat; @synthesize repFieldSquat; @synthesize workingOneRMSquat; @synthesize weightFieldMilitaryPress; @synthesize repFieldMilitaryPress; @synthesize workingOneRMMilitaryPress; @synthesize repFieldDeadlift; @synthesize workingOneRMDeadlift; @synthesize weightFieldBenchPress; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)viewDidUnload { [self setWeightFieldDeadlift:nil]; [self setRepFieldDeadlift:nil]; [self setWorkingOneRMDeadlift:nil]; [self setWeightFieldDeadlift:nil]; [self setRepFieldBenchPress:nil]; [self setWeightFieldBenchPress:nil]; [self setWorkingOneRMBenchPress:nil]; [self setWeightFieldSquat:nil]; [self setRepFieldSquat:nil]; [self setWorkingOneRMSquat:nil]; [self setWeightFieldMilitaryPress:nil]; [self setRepFieldMilitaryPress:nil]; [self setWorkingOneRMMilitaryPress:nil]; [super viewDidUnload]; // Release any retained subviews of the main view. } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } - (IBAction)calculateOneRM:(id)sender { float dw = [[weightFieldDeadlift text]floatValue]; float dr = [[repFieldDeadlift text]floatValue]; float d = (dw * dr * 0.0333) + dw; NSLog(@"Deadlift: %f", d); NSString *deadlift = [[NSString alloc]initWithFormat:@"%f", d]; [workingOneRMDeadlift setText:deadlift]; float bpw = [[weightFieldBenchPress text]floatValue]; float bpr = [[repFieldBenchPress text]floatValue]; float bp = (bpw * bpr * 0.0333) + bpw; NSLog(@"Bench Press: %f", bp); NSString *benchPress = [[NSString alloc]initWithFormat:@"%f", bp]; [workingOneRMBenchPress setText:benchPress]; float sw = [[weightFieldSquat text]floatValue]; float sr = [[repFieldSquat text]floatValue]; float s = (sw * sr * 0.0333) + sw; NSLog(@"Squat: %f", s); NSString *squat = [[NSString alloc]initWithFormat:@"%f", s]; [workingOneRMSquat setText:squat]; float mpw = [[weightFieldMilitaryPress text]floatValue]; float mpr = [[repFieldMilitaryPress text]floatValue]; float mp = (mpw * mpr * 0.0333) + mpw; NSLog(@"Military Press: %f", mp); NSString *militaryPress = [[NSString alloc]initWithFormat:@"%f", mp]; [workingOneRMMilitaryPress setText:militaryPress]; } @end

文件的所有者类已经声明为ANKYViewController。链接出口等是通过控制拖动而不是手动编码(我花了太多时间后放弃了)。

File's owner class is already stated as ANKYViewController. Linking the outlets etc was by control dragging instead of manually coding (I gave up after spending too many hours).

错误:

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

没有代码的复制和粘贴,并且在任何地方都没有提到repsField(而不是repFieldxxx)当然令人痛苦。

There's no copy and pasting of code, and it's certainly distressing that there is no mentioning of "repsField"(instead of repFieldxxx) anywhere.

我希望这是足够的信息为了帮助找到解决方案,因为我花了几天时间查看其他人的解决方案但没有成功。

I hope that this is enough information to help lead to a solution, as I've spent days looking through other people's solutions with no success.

谢谢。

推荐答案

看起来问题是有人正在使用密钥访问 UIApplication 实例( repsField )不符合KVC。

Looks like the problem is that someone is accessing the UIApplication instance with a key (repsField) that is not KVC compliant.

更新我认为您甚至不需要子类添加断点。转到断点导航器并为符号 - [UIApplication setValue:forUndefinedKey:] 添加符号断点,然后运行应用程序。

Update I don't think you even need to subclass to add a breakpoint. Go to the breakpoint navigator and add a symbolic breakpoint for symbol -[UIApplication setValue:forUndefinedKey:] and then run the application.

我认为您可以通过继承 UIApplication 来调试它,并在 setValue:forUndefinedKey:方法。

I think you can debug it by subclassing UIApplication and set a breakpoint in a dummy override of the setValue:forUndefinedKey: method.

在您调用 UIApplicationMain 的文件中添加此类:

In the file where you call UIApplicationMain add this class:

@interface TestApplication : UIApplication @end @implementation TestApplication - (void)setValue:(id)value forUndefinedKey:(NSString *)key { [super setValue:value forUndefinedKey:key]; // set breakpoint here } @end

然后改变第三个参数 UIApplicationMain 到 @TestApplication,例如:

And then change the third argument to UIApplicationMain to @"TestApplication", for example:

UIApplicationMain(argc, argv, @"TestApplication", NSStringFromClass([AppDelegate class]));

现在运行应用程序,它应该进入调试器,你应该能够看到调用堆栈导致它。

Now run the application and it should break into to debugger and you should be able to see the call stack causing it.

更多推荐

此类不是密钥XXX的密钥值编码兼容

本文发布于:2023-11-26 19:03:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634807.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:密钥   此类   XXX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!