I'm using the dropbox API for iOS to asynchronously download images for my tableview. When I pop my tableview controller from my navigation controller while the images are downloading, my app crashes. I debugged and found out the problem was an objective c message([DBRequest connectionDidFinishLoading:]) sent to a deallocated object(zombie). How do I fix this?
UPDATE:
I called the loadThumnail:ofSize:intoPath: method from rest client to download thumbnails in my tableView:cellForRowAtIndexPath: delegate method to download my thumbnails. restClient:loadedThumbnail:destPath: delegate method gets called when the thumbnails are loaded and I update my datasource then reload my tableview. The crash happens when I pop my tableview controller from my navigation controller while the images are downloading. I tried calling cancelAllRequest from my rest client, but it doesn't work. Any ideas on how to fix this?
- (void)restClient:(DBRestClient*)client loadedThumbnail:(NSString*)destPath {
UIImage *image = [UIImage imageWithContentsOfFile:destPath];
for (_RemoteFileObject *obj in self.objArray) {
if ([obj.thumbnailDownloadPath isEqualToString:destPath]) {
obj.thumbnail = image;
break;
}
}
[self.tableView reloadData];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//code to dequeue cell
//called load thumbnail method here
[[self restClient] loadThumbnail:obj.thumbnailURL ofSize:@"m" intoPath:obj.thumbnailDownloadPath];
}
UPDATE 2:
- (IBAction)goBack:(id)sender {
[[self restClient]cancelAllRequests];
[self.navigationController popViewControllerAnimated:YES];
}