它首先运行但后来又出现错误。这就是日志所说的
“2014-01-26 17:43:23.264更高或更低[26812:70b] * 由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[setValue:forUndefinedKey:]:对于键输入,此类不符合键值编码。'“
#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