0

私はすべてのプログラミングの初心者で、Big Nerd Ranch Books から独学で学んだことを実装しようとしています。しかし、私はこの問題に本当に困惑しています。はい、このフォーラムや他のフォーラムで可能な解決策を検索しましたが、成功しませんでした. コードは次のとおりです。

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:

#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 として指定されています。コンセントなどのリンクは、手動でコーディングするのではなく、コントロールをドラッグすることでした (あまりにも多くの時間を費やしてあきらめました)。

エラー:

*** 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 の代わりに) がどこにも言及されていないことは確かに苦痛です。

私は他の人の解決策を何日も見て成功しなかったので、これが解決策につながるのに役立つ十分な情報であることを願っています.

ありがとう。

4

2 に答える 2

4

KVC に準拠していないUIApplicationキー ( ) を使用して誰かがインスタンスにアクセスしていることが問題のようです。repsField

更新ブレークポイントを追加するためにサブクラス化する必要さえないと思います。ブレークポイント ナビゲーターに移動し、symbol のシンボリック ブレークポイントを追加してから-[UIApplication setValue:forUndefinedKey:]、アプリケーションを実行します。

UIApplicationサブクラス化してメソッドのダミーオーバーライドにブレークポイントを設定することでデバッグできると思いますsetValue:forUndefinedKey:

呼び出すファイルに、次のUIApplicationMainクラスを追加します。

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

次に、3 番目の引数を に変更しますUIApplicationMain@"TestApplication"次に例を示します。

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

ここでアプリケーションを実行すると、デバッガーに割り込む必要があり、その原因となっているコール スタックを確認できるはずです。

于 2012-06-30T16:41:05.290 に答える
1

このエラーメッセージが表示された場合、xibファイルまたはストーリーボードの接続が不良であることがよくあります。これは、MainWindow.xibファイルが含まれ、ファイルの所有者がUIApplicationクラスとして設定されている古い例だと思います。そのxibにrepsFieldは、ファイルの所有者で呼び出されたアウトレットへの接続が存在する可能性があります。もちろん、これは実際のクラスの何とも一致しません。

于 2012-06-30T17:03:17.257 に答える