I have multiple sections, there are 10 rows on each there. But, they do not move smoothly when scrolling the table. They stop sometimes for second. Can anyone help me figure out why?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"CustumCell";
CustumCell *cell = (CustumCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustumCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if ([tableDataArray count] == 0) {
} else {
NSInteger index = indexPath.section * 10 + indexPath.row;
NSString * newsValue =[[tableDataArray objectAtIndex:index]objectForKey:@"NewsValue"];
NSDictionary * newsDict =(NSDictionary *)[newsValue JSONValue];
cell.newsTitleLabel.text = [[tableDataArray objectAtIndex:index]objectForKey:@"Title"];
UIImage *image;
NSString *userString =[newsDict objectForKey:@"imgUrl"];
if([[ImageCache sharedImageCache] DoesExist:userString] == true) {
image = [[ImageCache sharedImageCache] GetImage:userString];
cell.newsImage.image = [ImageResizer squareImageTo:image :CGSizeMake(75, 75)];
} else {
NSURL *url = [NSURL URLWithString:userString];
NSURLSessionTask *task8 = [[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (data) {
UIImage *image = [UIImage imageWithData:data];
if (image) {
dispatch_async(dispatch_get_main_queue(), ^{
CustumCell *updateCell = (id)[tableView cellForRowAtIndexPath:indexPath];
if (updateCell)
updateCell.newsImage.image = [ImageResizer squareImageTo:image :CGSizeMake(75, 75)];
[[ImageCache sharedImageCache] AddImage:userString :image];
});
}
}
}];
[task8 resume];
}
}
return cell;
}