1

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];


}
iamarnold
  • 705
  • 1
  • 8
  • 22
  • Hard to say confidently without a better understanding of your code, but perhaps you should use `DBRestClient.cancelAllRequests` before removing the view controller with active requests. – Greg Nov 18 '15 at 20:43
  • @Greg I updated my question with code. – iamarnold Nov 19 '15 at 14:50
  • Can you share the code where you pop your `TableViewController`, including where you tried `cancelAllRequests`? `cancelAllRequests` calls `cancel` on all of the `NSURLConnection` that `DBRequest` uses, and according to the docs ( https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/index.html#//apple_ref/occ/instm/NSURLConnection/cancel ) that should prevent any further delegate method calls. – Greg Nov 20 '15 at 00:06
  • (Also, I'm assuming it was just a typo here, but just to make sure, you used "cancelAllRequests" and not "cancelAllRequest", as you have in your updated question text, right?) – Greg Nov 20 '15 at 00:07
  • @Greg I added my code that pops my table view controller. – iamarnold Nov 20 '15 at 14:35
  • Hm, based on the documentation I would expect `cancelAllRequests` to prevent `NSURLConnection` from sending `connectionDidFinishLoading`... Maybe another solution would be to keep your `restClient` around longer? Otherwise, perhaps debugging with Zombie objects enabled would yield some useful debugging information (e.g., https://stackoverflow.com/questions/25994549/enable-and-debug-zombie-objects-in-ios-using-xcode-5-1-1 ). – Greg Nov 20 '15 at 22:28

0 Answers0