加载视图时获取 EXC_BAD_ACCESS (MBProgressHUD+ASIHTTPRequest)
Greetz,
我目前在管理 mainViewController 上的“加载”屏幕(用户访问的第一个视图)时遇到问题。所以基本上第一个视图下载图像并将其放在 UIImageView 上。当发生这种情况时,会显示 MBProgressHUD。现在,用户转到带有自己的控制器的第二个视图。用户上传图像并返回。当用户返回到 mainView 时,mainView 会重新加载,因此不会显示与之前相同的图像。因此从逻辑上讲,“正在加载”MBProgressHUD 也应该显示。尽管如此,它在显示之前就崩溃了,在进行转换时它崩溃了。
问题是,仅当我实现了 MBProgressHUD 时,才会出现错误 exc_bad_access (肯定是内存管理问题,但我似乎不明白......)这些是包含相关代码的段:
mainViewController.m
- (void)viewDidLoad {
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = @"Please Wait";
[HUD showWhileExecuting:@selector(loadingOfImageAndInformation) onTarget:self withObject:nil animated:YES];
[super viewDidLoad];
}
- (void) loadingOfImageAndInformation {
// [...] get URL and blabla.
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:imageURL];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestLoadDone:)];
[request setDidFailSelector:@selector(requestLoadWentWrong:)];
[request setDownloadProgressDelegate:HUD];
[request startAsynchronous];
}
- (void)hudWasHidden {
// Remove HUD from screen when the HUD was hidded
[HUD removeFromSuperview];
[HUD release];
// HUD = nil; I tried this because I found it on another
// answer in S.O. but it didn't quite work.
// I don't think it is the same case.
// I also tried putting this on the dealloc method and
// the didReceiveMemoryWarning to no avail...
}
这是另一个问题处理类似的问题,但并没有真正解决我的问题。
非常感谢您今后的帮助!!
Greetz,
I am currently having issues managing a "Loading" screen on my mainViewController (The first view the user accesses.) So basically the first view downloads an image and puts it on a UIImageView. While this happens the MBProgressHUD is displayed. Now then, the user goes to a secondView with its own controller. The user uploads an image and goes back. When the user goes back to the mainView, the mainView gets reloaded so the same image as before is NOT displayed. So logically, the "Loading" MBProgressHUD should display aswell. Nonetheless it crashes before it can even let it display, it crashes while making the transition.
The thing is the error exc_bad_access comes only if I have the MBProgressHUD implemented (must be a problem with memory management but I don't seem to get it...) These are the segments with the code in question:
mainViewController.m
- (void)viewDidLoad {
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = @"Please Wait";
[HUD showWhileExecuting:@selector(loadingOfImageAndInformation) onTarget:self withObject:nil animated:YES];
[super viewDidLoad];
}
- (void) loadingOfImageAndInformation {
// [...] get URL and blabla.
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:imageURL];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestLoadDone:)];
[request setDidFailSelector:@selector(requestLoadWentWrong:)];
[request setDownloadProgressDelegate:HUD];
[request startAsynchronous];
}
- (void)hudWasHidden {
// Remove HUD from screen when the HUD was hidded
[HUD removeFromSuperview];
[HUD release];
// HUD = nil; I tried this because I found it on another
// answer in S.O. but it didn't quite work.
// I don't think it is the same case.
// I also tried putting this on the dealloc method and
// the didReceiveMemoryWarning to no avail...
}
This is the other question that treats a similar problem but that didn't really solve mine.
Thank you very much for your future help!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉,我还没有阅读整个问题。通常当你得到 EXC_BAD_ACCESS 时,很容易判断你是否启用了 NSZombie。如果它没有帮助,请发表评论,我会看看是否可以改进我的答案。
要激活 NSZombie,请执行以下操作:
名称:NSZombieEnabled
值:YES
然后照常运行您的应用程序,当它崩溃时,它应该告诉您哪个已释放的对象收到了释放消息。
I'm sorry but I haven't read the entire question. Usually when you get EXC_BAD_ACCESS it will be pretty easy to figure out if you enable NSZombie. If it doesn't help drop a comment and I'll see if I can improve my answer.
To activate NSZombie do the following:
Name: NSZombieEnabled
Value: YES
Then run your app as usual and when it crashes it should tell you which deallocated object received the release message.
您将
HUD
设置为request
的 downloadProgressDelegate。也许在您释放HUD
后,request
会尝试向其发送消息。如果您在调试器中运行代码,崩溃时获得的堆栈跟踪应该会告诉您是否是这种情况。You set
HUD
as the downloadProgressDelegate ofrequest
. Perhapsrequest
tries to send a message to it after you releaseHUD
. If you run your code in the debugger, the stack trace you get on the crash should tell you if this is the case.