When using reloadrowsatindexroads: withrowanimation:, when pulling down, the cell changes strangely, with large gaps.

  ios, question

I made a UITableView similar to Weico and customized UITableViewCell.
Because the pictures in Cell are loaded asynchronously, they are executed after the pictures are loaded.reloadRowsAtIndexPaths:withRowAnimation:To control the Cell height.
However, there is a problem. It is normal to pull the Cell up (from top to bottom). After the picture is loaded, the height of the Cell changes. However, when the Cell is pulled down (from bottom to top), the Cell changes strangely. There is a large blank under the cell. thx a ton. Please look at the picture:

附图

EDIT: Moreover, if the Internet is pulled too fast, it will crash

*** Terminating app due to uncaught exception 'NSRangeException', reason:
 
 '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

UPDATE:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
 if(IS_LAST_ROW){
 return 40.0;
 bracket
 MStatusItem *status = [_data_array objectAtIndex:indexPath.row];
 Cgfloat imageheight = [[_ imageheights valueforkey: [nsstringstringwithformat: @ "percent @", status.ID]] floatValue]];
 
 CGFloat height = MAX([status.getPlainText sizeWithFont:[UIFont systemFontOfSize:16.0f] constrainedToSize:CGSizeMake(320.0f - (20.0f * 2),  20000.0f) linebreak mode: nslinebreak bywordwrapping. height, 44.0f) plus (20.0f * 1.5);
 height = [status hasImage] ?  Height plus 50 plus imageHeight: height plus 40;
 if(status.rtweet !  = (id)[NSNull null]){
 NSString *retweetText = [status.rtweet valueForKey:@"text"];
 CGFloat retweetTextSize = MAX([retweetText sizeWithFont:[UIFont systemFontOfSize:16.0f] constrainedToSize:CGSizeMake(320.0f - (20.0f * 2),  20000.0f) linebreak mode: nslinebreak bywordwrapping. height, 44.0f) plus (20.0f * 1.5);
 constrainedToSize:CGSizeMake(260.0, 2000.0f)];
 Height plus = retweetTextSize;
 if(status.hasRetweetImage){
 Height plus = imageHeight;
 bracket
 bracket
 return height;
 bracket

ImageHeights is a Dictionaray that stores the height of the loaded image.

tableView:cellForRowAtIndexPath:

__weak typeof(cell) weakCell = cell;
 [cell.weiboImageView setImageWithURL:[NSURL URLWithString: status.tnpic]
 placeholderImage:[UIImage imageNamed:@"placeholder.png"]completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
 Weiboimageview.frame = cgrrectake (65.0, contentsize.height plus 30.0f, image.size.width, image.size.height);
 [self.imageheights setvalue: [nsnumbernumbernumberwithfloat: image.size.height] forge: [nsstringstringwithformat: @ "percent @", status.ID]];
 [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
 
 bracket
 ];

Cell reuse:

static NSString * ID = @"WeiboCustomCellIdentifier";
 //[tableView registerClass:[WeiboCustomCell class] forCellReuseIdentifier:ID];
 WeiboCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
 if(cell == nil){
 cell = [[WeiboCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
 }else{
 
 cell.textLabel.text = nil;
 while ([cell.contentView.subviews lastObject] !  = nil) {
 [(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];
 bracket
 bracket

Crash’s reason is that the array is out of bounds and cell is blank because the problem of height calculation is in the method.tableView:heightForRowAtIndexPath:According to the picture after loading, you can calculate the height of cell, and you can paste the code in you to see if there is any problem