我正在UIAlertView
向用户显示一个带有“确定”按钮的用户,当用户按下按钮时,我希望我的委托方法执行操作。然而,目前当用户按下“确定”按钮时,应用程序崩溃并出现以下错误:
Thread 1: EXC_BAD_ACCESS (code=1, address=0xb)
这是我的代码,警报视图显示良好的按钮等,但是一旦按下按钮,这就是我得到的错误。它几乎就像一个断点,但如果我单击前进按钮,什么也不会发生。
//.h
@interface ErrorHandling : NSObject <UIAlertViewDelegate> {
//.m
#define myAlertViewsTag 0
- (void)recivedErrorCode:(int)errorCode MethodName:(NSString *)methodName {
switch (errorCode) {
case 1: {
NSLog(@"ERROR = 1");
message = [[UIAlertView alloc] initWithTitle:@"Error 1:"
message:@"The supplied registration code does exist."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[SVProgressHUD dismiss];
[message show];
}
break;
case 2: {
NSLog(@"ERROR = 2");
message = [[UIAlertView alloc] initWithTitle:@"Error 2:"
message:@"Your registration is no longer valid."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
message.tag = myAlertViewsTag;
[SVProgressHUD dismiss];
[message show];
}
break;
default:
break;
}
}
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (message.tag == myAlertViewsTag) {
if (buttonIndex == 0) {
// Do something when ok pressed
NSLog(@"DONE 1");
} else {
// Do something for ok
NSLog(@"DONE 2");
}
} else {
// Do something with responses from other alertViews
NSLog(@"DONE 3");
}
}
更新:这就是我如何从我的连接类中调用上面代码所在的类。
// Do whatever you need to with the error number
ErrorHandling *errorHandling = [[ErrorHandling alloc] init];
[errorHandling recivedErrorCode:errorRecivedFromServerInt MethodName:methodName];