格爾茨,當獲得EXC_BAD_ACCESS加載視圖(MBProgressHUD + ASIHTTPRequest)
目前我有我的mainViewController管理「加載」屏幕問題(用戶訪問的第一個觀點。)所以基本上第一個視圖下載圖像並把它放在一個UIImageView上。發生這種情況時,會顯示MBProgressHUD。現在,用戶使用自己的控制器進入第二個視圖。用戶上傳圖像並返回。當用戶返回mainView時,mainView將被重新加載,因此不會顯示與之前相同的圖像。因此在邏輯上,「加載」MBProgressHUD應該也會顯示。儘管如此,它甚至可以讓它顯示之前崩潰,它在轉換時崩潰。
事情是錯誤exc_bad_access只有當我有MBProgressHUD實現(必須是內存管理的問題,但我似乎並沒有得到它......)這些是有問題的代碼段:
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...
}
這是治療類似的問題,但並沒有真正解決我的其他question。
非常感謝您的未來幫助!
如果你需要構建堆棧讓我知道。 – Joze 2011-02-11 14:09:59
HUD是保留財產嗎? – 2011-02-11 16:15:53