0

当我在模拟器中运行我的应用程序时,我遇到了一个问题:

-[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;
}

@结尾

4

1 回答 1

1

该错误表明选择器验证:已发送到 ViewController 的实例。在大多数情况下,这意味着该消息是针对某个其他对象的,但该对象被释放得太早,并且 ViewController 的一个实例被分配在同一地址。

Zombies 工具应该有助于找到过早释放的对象。如果您在项目的其他地方有一个 -verify: 方法,那么释放的对象可能是该类的一个实例。

于 2013-08-08T18:58:46.947 回答