UIImage in uitableViewcell slows down scrollable table

Hello, I'm trying to get a facebook user profile picture in the cell.image table. But it slows down the scroll table view. Then I used the Asynchronous Image Download link. But I am confused how to use this in a table method

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; } cell.textLabel.font = [ UIFont fontWithName:@"Arial" size:10.0]; cell.textLabel.numberOfLines = 0; cell.textLabel.text = [NSString stringWithFormat:@"%@",[(Facebook *)[dummyArray objectAtIndex:indexPath.row] sender]]; cell.detailTextLabel.text =[NSString stringWithFormat:@"%@",[(Facebook *)[dummyArray objectAtIndex:indexPath.row] post]]; NSString *get_string = [NSString stringWithFormat:@"%@/picture",[(Facebook *)[dummyArray objectAtIndex:indexPath.row]senderId]]; AsynchronousImageView *image = [[AsynchronousImageview alloc]init]; [image loadImagewithUrlString:getString]; FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:get_string withGetVars:nil]; UIImageView *image_view = [[UIImageView alloc] initWithImage:fb_graph_response.imageResponse]; cell.imageView.image = image_view.image; [image_view release]; return cell; } 
0
source share
3 answers

It slows down because you set image every time cellForRowAtIndexPath: is cellForRowAtIndexPath: . Add the image to the imageView cell only inside the if (cell == nil) block. Then you will see the scroll improvement.

+4
source
  AsynchronousImageView *image = [[AsynchronousImageview alloc]init]; [image loadImagewithUrlString:getString]; FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:get_string withGetVars:nil]; UIImageView *image_view = [[UIImageView alloc] initWithImage:fb_graph_response.imageResponse]; cell.imageView.image = image_view.image; 

This code creates the described problem ..... try this approach ... as soon as any image is uploaded, save it in any temporary folder in the document directory (enter the name of the ur-image so that you can uniquely identify each of them) .. .. and when you need to customize the cell, just accept the form form in the temp folder every time the celForRowAtIndexPath method is celForRowAtIndexPath .... don't use

  UIImageView *image_view = [[UIImageView alloc]; 

This does not make sense since you are not using it (you just use its .image property) .... also, if possible, collect all your data in viewDidLoad in this way, you can further improve performance

0
source

Are you sure the asynchronous image is causing problems? Comment on the image portion of the asynchronous image and see if it is part of the FbGraphResponse.

I see that every time you create an image to respond to the graph, and this can lead to a slowdown.

0
source

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


All Articles