Wednesday, November 27, 2013

http://stackoverflow.com/questions/14547570/ios-tableview-with-multiple-images-per-row-sdwebimage

http://stackoverflow.com/questions/14547570/ios-tableview-with-multiple-images-per-row-sdwebimage

iOS: TableView with multiple Images per Row (SDWebImage)


I try to load the images via SDWebImage for each cell.

The loading procedures are all done in my custom UITableViewCell - not in the UITableViewController. From the cellForRowAtIndexPath i just call [cell setup] which executes the following code in the current cell:

  NSArray *imageViews = [NSArray arrayWithObjects:self.imageView1, self.imageView2, self.imageView3, self.imageView4, nil];    for (int i = 0; i < self.products.count; i++) {        Product *currentProduct = [self.products objectAtIndex:i];      UIImageView *currentImageView = [imageViews objectAtIndex:i];        NSString *thumbURL = [[CommonCode getUnzippedDirectory] stringByAppendingPathComponent:currentProduct.collectionFolderName];      thumbURL = [thumbURL stringByAppendingPathComponent:thumbFolder];      thumbURL = [thumbURL stringByAppendingPathComponent:currentProduct.product_photo];        [currentImageView setContentMode:UIViewContentModeScaleAspectFit];        [currentImageView setImageWithURL:[NSURL fileURLWithPath:thumbURL]                     placeholderImage:[UIImage imageNamed:@"placeholder.png"]];  }

The images are all stored in the documents directory and are not greater than max. 500Kb.

Problem:

My Problem is that when I scroll through my tableview it suddenly crashes and I don't know why. Enabling a symbolic breakpoint for all exceptions shows that it crashes because of one line in SDWebImage. Unfortunately there isn't a debugger output: (It crashes where the image is allocated)

  UIImage *image = nil;  if ([imageOrData isKindOfClass:[NSData class]])  {      image = [[UIImage alloc] initWithData:(NSData *)imageOrData];  }

I also tried to load images via dispatch_asnyc with a similar result. Is it possible that it has something to do with concurrent file operations?

Additionally I get Memory Warnings when I scroll very fast so that I have to clear the cache of SDWebImage. At the same time it stops at the code line in SDWebImage mentioned above.

I already searched the web for 2 days now and I didn't find something useful. I would be glad for some hints to fix this problem. If somebody needs additional data such as crash reports or something, just let me know and I will provide them quickly.

asked Jan 27 at 12:58
Bins Ich
3931824
 
Are you using ARC? When the app crashes, what's the message (EXC_BAD_ACCESS, sig fault, etc.)? Did you try enabling zombies? –  Mota Jan 27 at 13:08 
 
yeah I am using ARC. Unfortunately there is now message. I only get several Memory Warnings in my TableViewController until the app crashes. Additionally a symbolic breakpoint for all exceptions shows that this one line in SDWebImage makes troubles (it says: Thread 3: Stopped at breakpoint 0). The same occurs when I use an async queue instead of SDWebImage - it makes trouble when i want to allocate the image. – Bins Ich Jan 27 at 13:32
 
I think the reason why it stops when allocating the image is the low memory. But shouldn't SDWebImage handle this? –  Bins Ich Jan 27 at 13:36
1  
I agree with Bins Ich that the app is using too much memory. Even though the image file size is 500k (which seems large for a thumbnail image), it's size in memory could be much larger (size in memory = width x height x bytes/pixel). Suggest creating another version of the images being put in the table view that are the same size as the image views as a test. I suspect you will not have the same issue. –  bobnoble Jan 27 at 14:06
1  
What you're trying to do strikes me as a collection view. Are you sure you want to use a sectioned table view? Apple provides built in functionality for this now with Collection Views to efficiently manage dequeueing, scrolling, etc. –  Sean Jan 27 at 15:35

No comments:

Post a Comment