0

It runs at first but then goes back to an error. This is what the log says

"2014-01-26 17:43:23.264 Higher or Lower[26812:70b] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key enter.'"

#import "ViewController.h"

int answer = 0;
int guess = 0;
int turn = 0;



@interface ViewController ()

@end

@implementation ViewController


- (void)viewDidLoad; {

       [super viewDidLoad];
       _higher.hidden = YES;
       _lower.hidden = YES;
       answer = arc4random() % 100 + 1;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
       [_labelGuess resignFirstResponder];

}

- (void)didReceiveMemoryWarning
{
       [super didReceiveMemoryWarning];
       // Dispose of any resources that can be recreated.
}

- (IBAction)enterButton:(UIButton *)sender {

        NSString *input = _labelGuess.text;
        guess = [input intValue ];
        _labelGuess.text=input;

        if (guess > answer) {
            _lower.hidden = NO;
            _higher.hidden = NO;

    }
    else if (guess < answer) {
            _lower.hidden = YES;
            _higher.hidden = NO;
    }
    else {
            NSLog(@"Correct! The answer was %i", answer);
    }

        NSLog(@"The random value is %i", answer);
        scanf("%i", &guess);
}


@end

//HEADER FILE!

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UITextField *labelGuess;

@property (weak, nonatomic) IBOutlet UIImageView *chooseNumber;

@property (weak, nonatomic) IBOutlet UIImageView *higher;

@property (weak, nonatomic) IBOutlet UIImageView *lower;

- (IBAction)enterButton:(UIButton *)sender;


@end
MikeG
  • 15
  • 5
  • Check your connections in Interface Builder, and make sure all your outlets (particularly for the `UITextField`) are as they should be. Also, what is that `scanf()` call doing there? – Crowman Jan 27 '14 at 00:17
  • I got rid of the scant() The outlets seem fine to me, here is the header file... – MikeG Jan 27 '14 at 00:46
  • 1
    Search on the error: http://stackoverflow.com/search?q=NSUnknownKeyException+this+class+is+not+key+value+coding+compliant+for+the+key – rmaddy Jan 27 '14 at 00:51
  • Whoah. `answer`, `guess` and `turn` are global variables. Likely not what you need. Also, `scanf()` in an iOS app makes no sense. – bbum Jan 27 '14 at 01:05
  • Try adding an exception breakpoint and run again. Also, when is the `enterButton` method triggered ? – GoGreen Jan 27 '14 at 11:46
  • Breakpoint before #import "ViewController.h" still gets error. Also, why don't I need global variables and scant has been removed. enterButton is triggered at the end when the button is pressed? Couldn't finish that because I've been working on this error. Thanks! – MikeG Jan 27 '14 at 23:41
  • possible duplicate of [What does this mean? "'NSUnknownKeyException', reason: ... This class is not key value coding-compliant for the key X"](http://stackoverflow.com/questions/3088059/what-does-this-mean-nsunknownkeyexception-reason-this-class-is-not-key) – jtbandes Aug 03 '15 at 06:30

0 Answers0