I am Getting error message as follows...
“2014-01-28 21:17:56.878更高或更低2 [5869:70b] *由于未捕获的异常'NSUnknownKeyException'终止应用程序,原因:'[setValue:forUndefinedKey:]:此类是密钥enterButoonOut不符合密钥值编码。 * 首先抛出调用堆栈:“
//
// ViewController.m
// Higher or Lower 2
//
// Created by Michael Goedken on 1/27/14.
// Copyright (c) 2014 Michael Goedken. All rights reserved.
//
/
// Created by Michael Goedken on 1/27/14.
// Copyright (c) 2014 Michael Goedken. All rights reserved.
//
#import "ViewController.h"
int answer = 0;
int guess = 0;
int turn = 0;
BOOL timeStarted = NO;
@interface ViewController ()
@end
@implementation ViewController
- (IBAction)enterButton:(id)sender {
NSString *input = _labelGuess.text;
guess = [input intValue];
_previousLabel.text = [NSString stringWithFormat:@"%d",guess];
_labelGuess.text=@"";
turn++;
_guessesLabel.text = [NSString stringWithFormat:@"%d",turn];
if (timeStarted == NO){
seconds = 0;
timer = [NSTimer scheduledTimerWithTimeInterval:.001 target:self
selector:@selector(countUp) userInfo:nil repeats:YES];
}
timeStarted = YES;
if (guess < 1 || guess > 100){
_correct.hidden = YES;
_lower.hidden = YES;
_higher.hidden = YES;
_chooseNumber.hidden = YES;
_outOfRange.hidden = NO;
}
else if (guess > answer) {
_lower.hidden = NO;
_higher.hidden = YES;
_chooseNumber.hidden = YES;
_correct.hidden = YES;
_outOfRange.hidden = YES;
}
else if (guess < answer) {
_lower.hidden = YES;
_higher.hidden = NO;
_chooseNumber.hidden = YES;
_correct.hidden = YES;
_outOfRange.hidden = YES;
}
else {
_correct.hidden = NO;
_lower.hidden = YES;
_higher.hidden = YES;
_chooseNumber.hidden = YES;
_outOfRange.hidden = YES;
[timer invalidate];
_nextButtonOut.hidden = NO;
_enterButtonOut.hidden = YES;
_labelGuess.hidden = YES;
}
}
-(void) countUp {
milliSeconds ++;
seconds = milliSeconds / 1000;
minutes = seconds / 60;
remainingSeconds = seconds % 60;
remainingMilliSeconds = milliSeconds % 1000;
if (minutes > 0) {
_timerLabel.text = [NSString stringWithFormat:@"%2d:%.2d", minutes, remainingSeconds];
}
else {
_timerLabel.text = [NSString stringWithFormat:@"%2d:%.2d.%.3d", minutes,
remainingSeconds, remainingMilliSeconds];
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[_labelGuess resignFirstResponder];
}
- (void)viewDidLoad
{
[super viewDidLoad];
_labelGuess.keyboardType = UIKeyboardTypeNumberPad;
_higher.hidden = YES;
_lower.hidden = YES;
_correct.hidden = YES;
_outOfRange.hidden = YES;
answer = arc4random() % 100 + 1;
_nextButtonOut.hidden = YES;
NSLog(@"Answer %i", answer);
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)nextButton:(id)sender {
_correct.hidden = YES;
_lower.hidden = YES;
_higher.hidden = YES;
_chooseNumber.hidden = YES;enter code here
_outOfRange.hidden = YES;
_labelGuess.hidden = YES;
_guessesLabel.hidden = YES;
_previousLabel.hidden = YES;
_timerLabel.hidden = YES;
_nextButtonOut.hidden = YES;
_enterButtonOut.hidden = YES;
_background.hidden = YES;
_guesses.hidden = YES;
_previous.hidden = YES;
}
@end
//
// ViewController.h
// Higher or Lower 2
//
// Created by Michael Goedken on 1/27/14.
// Copyright (c) 2014 Michael Goedken. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
NSTimer *timer;
int seconds;
int minutes;
int remainingSeconds;
int milliSeconds;
int remainingMilliSeconds;
}
@property (weak, nonatomic) IBOutlet UIImageView *chooseNumber;
@property (weak, nonatomic) IBOutlet UITextField *labelGuess;
@property (weak, nonatomic) IBOutlet UIImageView *higher;
@property (weak, nonatomic) IBOutlet UIImageView *lower;
@property (weak, nonatomic) IBOutlet UIImageView *correct;
@property (weak, nonatomic) IBOutlet UIImageView *outOfRange;
@property (weak, nonatomic) IBOutlet UILabel *previousLabel;
@property (weak, nonatomic) IBOutlet UILabel *timerLabel;
@property (weak, nonatomic) IBOutlet UIButton *nextButtonOut;
@property (weak, nonatomic) IBOutlet UIButton *enterButtonOut;
@property (weak, nonatomic) IBOutlet UIImageView *background;
@property (weak, nonatomic) IBOutlet UILabel *previous;
@property (weak, nonatomic) IBOutlet UILabel *guessesLabel;
@property (weak, nonatomic) IBOutlet UILabel *guesses;
- (IBAction)nextButton:(id)sender;
- (IBAction)enterButton:(id)sender;
@end
答案 0 :(得分:0)
当发生一些事情时,我通常会收到此错误消息。
1)我拼错了segue.identifier的值,因为我要塞到另一个模块(不确定这适用于你的情况,但这是它总是让我的地方)。 2)如果您对故事板进行了更改,那么请删除代码中的值,在故事板中不会消除连接,您必须手动进入并从故事板中删除链接。要检查,只需右键单击(或按住Ctrl键单击)故事板中的每个元素,然后记下连接。
我的猜测是,如果你看一下故事板中的那个按钮,你会看到“enterButoonOut”而不是“enterButtonOut”
希望这有帮助!
格伦
答案 1 :(得分:0)
您输入了错误的enterButoonOut,根据您的声明,它必须是enterButtonOut:
@property (weak, nonatomic) IBOutlet UIButton *enterButtonOut;