我的应用程序有一个按钮,用于检查输入的值是否正确。有时它会导致它崩溃,但奇怪的是它以不规则的间隔发生(有时在第三次迭代,有时在第十次,有时从不)。
我在调试器中收到 EXC_BAD_ACCESS 错误。所以似乎有些东西在不应该的时候被释放了。按钮调用此函数:
- (IBAction)checkValue:(id)sender{
int actualDifference = [firstNumberString intValue] - [secondNumberString intValue];
actualDifferenceAsString = [NSString stringWithFormat:@"%d", actualDifference];
if ([answerTextField.text isEqualToString:actualDifferenceAsString])
{
UIAlertView *correctAlert = [[UIAlertView alloc] initWithTitle:@"matches"
message:@"next value."
delegate:nil
cancelButtonTitle:@"ok"
otherButtonTitles: nil];
[correctAlert show];
[correctAlert release];
}
else
{
UIAlertView *incorrectAlert = [[UIAlertView alloc]
initWithTitle:@"does not match"
message:@"next value."
delegate:nil
cancelButtonTitle:@"ok"
otherButtonTitles: nil];
[incorrectAlert show];
[incorrectAlert release];
}
使用僵尸指向第一个语句:
int actualDifference = [firstNumberString intValue] - [secondNumberString intValue];
有谁知道问题可能是什么?