加载视图时获取 EXC_BAD_ACCESS (MBProgressHUD+ASIHTTPRequest)

发布于 2024-10-17 03:33:21 字数 1669 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

楠木可依 2024-10-24 03:33:21

抱歉,我还没有阅读整个问题。通常当你得到 EXC_BAD_ACCESS 时,很容易判断你是否启用了 NSZombie。如果它没有帮助,请发表评论,我会看看是否可以改进我的答案。

要激活 NSZombie,请执行以下操作:

  1. 获取可执行文件的信息。
  2. 转到参数选项卡。
  3. 在“环境中设置的变量:”部分添加:

名称: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:

  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.

我们只是彼此的过ke 2024-10-24 03:33:21

您将 HUD 设置为 request 的 downloadProgressDelegate。也许在您释放 HUD 后,request 会尝试向其发送消息。如果您在调试器中运行代码,崩溃时获得的堆栈跟踪应该会告诉您是否是这种情况。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文