开发者

Getting EXC_BAD_ACCESS when loading view (MBProgressHUD+ASIHTTPRequest)

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 = [ASI开发者_Python百科HTTPRequest 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!!


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:

  1. Get info of the executable.
  2. Go to the arguments tab.
  3. In the "Variables to be set in the environment:" section add:

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.


You set HUD as the downloadProgressDelegate of request. Perhaps request tries to send a message to it after you release HUD. If you run your code in the debugger, the stack trace you get on the crash should tell you if this is the case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜