当我在模拟器中运行我的应用程序时,我遇到了一个问题:
-[ViewController verify:]: unrecognized selector sent to instance 0x75ca600
2013-08-08 09:31:14.890 Mathy[32061:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController verify:]: unrecognized selector sent to instance 0x75ca600'
但问题是它所引用的选择器甚至不存在于程序中。这是我的代码:
@interface ViewController : UIViewController
{
int number1;
int number2;
float result;
}
@property (strong, nonatomic) IBOutlet UILabel *questionType;
@property (strong, nonatomic) IBOutlet UILabel *number1Label;
@property (strong, nonatomic) IBOutlet UILabel *number2Label;
@property (strong, nonatomic) IBOutlet
UILabel *op;
@property (strong, nonatomic) UITextField *userInput;
@property (strong, nonatomic) IBOutlet UILabel *CorrectOrWrong;
-(IBAction)generateQuestion:(id)sender;
@end
@implementation ViewController
@synthesize questionType;
@synthesize number1Label;
@synthesize number2Label;
@synthesize op;
@synthesize userInput;
@synthesize CorrectOrWrong;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.CorrectOrWrong.hidden = YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)generateQuestion:(id)sender
{
self.CorrectOrWrong.hidden = YES;
self.questionType.text = @"";
self.number1Label.text = @"";
self.number2Label.text = @"";
self.op.text = @"";
self.userInput.text = @"";
number1 = arc4random_uniform(21);
number2 = arc4random_uniform(21);
int operation = arc4random_uniform(4);
switch (operation) {
case 0:
result = number1+number2;
self.questionType.text = @"Addition";
self.number1Label.text = [NSString stringWithFormat:@"%d", number1];
self.number2Label.text = [NSString stringWithFormat:@"%d", number2];
self.op.text = @"+";
break;
case 1:
result = number1-number2;
self.questionType.text = @"Subtraction";
self.number1Label.text = [NSString stringWithFormat:@"%d", number1];
self.number2Label.text = [NSString stringWithFormat:@"%d", number2];
self.op.text = @"-";
break;
case 2:
result = number1*number2;
self.questionType.text = @"Multiplication";
self.number1Label.text = [NSString stringWithFormat:@"%d", number1];
self.number2Label.text = [NSString stringWithFormat:@"%d", number2];
self.op.text = @"*";
break;
case 3:
result = number1/number2;
self.questionType.text = @"Division";
self.number1Label.text = [NSString stringWithFormat:@"%d", number1];
self.number2Label.text = [NSString stringWithFormat:@"%d", number2];
self.op.text = @"÷";
break;
default: result=number1+number2;
self.questionType.text = @"Addition";
self.number1Label.text = [NSString stringWithFormat:@"%d", number1];
self.number2Label.text = [NSString stringWithFormat:@"%d", number2];
self.op.text = @"+";
break;
}
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
if([self.userInput.text intValue])
{
self.CorrectOrWrong.hidden = NO;
self.CorrectOrWrong.text = @"Great Job!";
}
else
{
self.CorrectOrWrong.hidden = NO;
self.CorrectOrWrong.text = @"Uh oh! Incorrect!";
}
return YES;
}
@结尾