Updating UITableViewCell while executing lazy image

I'm having some problems updating UITableViewCells after asynchronously loading a cell image. I use custom UITableViewCells like this:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"productCell";
    MainTableViewCell *cell = (MainTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[MainCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"productCell"] autorelease];
    }
}

I have a class that is a UITableViewCell, and then a class that executes the entire drawing. This is an example of Apple code called "AdvancedTableViewCells", and I'm doing the composition.

I have images in my cells that I upload asynchronously using an example Apple code called "LazyTableImages". Here is the delegate that should update the cell:

- (void)coverImageDidLoad:(NSIndexPath *)indexPath {
    CoverImageAsyncLoader *coverImageAsyncLoader = [imageDownloadsInProgress objectForKey:indexPath];
    if (coverImageAsyncLoader != nil) {
        MainTableViewCell *cell = (MainTableViewCell *)[self.tableView cellForRowAtIndexPath:coverImageAsyncLoader.indexPathInTableView];

        // Display the newly loaded image
  if (coverImageAsyncLoader.products.coverImage != nil) {
   cell.productCover = coverImageAsyncLoader.products.coverImage;
  } else {
   cell.productCover = blankCoverImage;
  }
    }
}

. , , , , . :

 [cell setNeedsDisplay];
 [cell.contentView setNeedsDisplay];

:

 cell = [[[MainCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"productCell"] autorelease];

.

:( , .

+3
1

(, myCellIndexPath.section myCellIndexPath.row), UITableView -reloadRowsAtIndexPaths:withRowAnimation:.

:

[tableView beginUpdates];
NSUInteger _path[2] = {myCellIndexPath.section, myCellIndexPath.row};
NSIndexPath *_indexPath = [[NSIndexPath alloc] initWithIndexes:_path length:2];
NSArray *_indexPaths = [[NSArray alloc] initWithObjects:_indexPath, nil];
[_indexPath release];
[tableView reloadRowsAtIndexPaths:_indexPaths withRowAnimation:UITableViewRowAnimationRight];
[_indexPaths release];
[tableView endUpdates];

, , .

, (UITableViewRowAnimationFade, UITableViewRowAnimationNone ..). UITableViewRowAnimation.

+3

Source: https://habr.com/ru/post/1726014/


All Articles