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!!
You set
HUDas the downloadProgressDelegate ofrequest. Perhapsrequesttries 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.