我不明白为什么这给了我一个 EXC_BAD_ACCESS。基本背景,我收集并处理了一些信息,然后使用模态视图让用户确认是否要继续。
我在导航栏上有一个名为 continue 的按钮,它调用我的数据准备功能。
- (void)viewDidLoad {
//Other stuff
UIBarButtonItem *next = [[UIBarButtonItem alloc]
initWithTitle:@"Next"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(prepData)];
self.navigationItem.rightBarButtonItem = next;
[next release];
[super viewDidLoad];
}
准备数据:
-(void)prepData{
/*
There's a bunch of stuff going on here, if "mensaje" is not an empty NSString, there is some kind of error that wont let me go on, if not, everything in the data is fine
*/
if(![mensaje isEqualToString:@""]){
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:nil
message:mensaje
delegate:nil
cancelButtonTitle:@"Aceptar"
otherButtonTitles:nil];
[alert show];
[alert release];
}else{
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"¿Esta seguro que desea realizar estas operaciones?"
delegate:self
cancelButtonTitle:@"Cancelar"
destructiveButtonTitle:@"Aceptar"
otherButtonTitles:nil];
[actionSheet showInView:self.view];
[actionSheet release];
}
}
如果我调试,我可以一直通过 prepData(),只要我按下继续,我就会得到一个 EXC_BAD_ACCESS。如果我注释掉 [actionSheet release];我没有得到例外,但据我所知,就像警报视图一样,操作表“一直存在”直到它们显示出来。
至少我读过的所有书籍都这样说,但很可能我不理解自动发布中的某些内容。
仅供参考,弹出警报就好了。
有人知道这里发生了什么吗?
谢谢,斯特凡诺。
编辑:想通了,上面的操作表和警报视图的代码很好,问题是我正在发布一些后来试图自动发布的东西。
我有执行此操作的 for 循环:
for(someConditions){
NSString *montoFormateado = [[[NSString alloc] initWithFormat:@"%.2lf",[monto doubleValue]] stringByReplacingOccurrencesOfString:@"." withString:@","];
[_postBuild setObject:[NSString stringWithString:montoFormateado] forKey:[NSString stringWithString:iidvar]];
[montoFormateado release];
}
postBuild = [_postBuild mutableCopy];
[_postBuild release];
现在,似乎错误在于通过使用 [NSString strintWithString:montoFormateado] 我将该字符串留待稍后自动释放,但是当我发布 _postBuild 该字符串也被释放时,我将其删除并仅使用了 setObject:montoFormateado并且工作正常。
它的内存泄漏,但我认为这是一个不同的问题,exc_bad_access 得到了解决。