How to add an activity indicator to an image in a UITableView?

I created a Custom tableView and using my own tableView class in the Other class to display the tableView ..

I download the image from the server and display it in tableViewRow .. each image is different from it.

Only 7 out of 10 images will appear on the screen, and when I scroll down, the first 3 images are repeated for some time, and when these images are loaded, it shows the correct images .. but first, before the new image images appear, I want to put an activity indicator, to show that images are loading instead of old images.

I want to add activity Indicator instead of image until image gets the load ..

My code ...

 self.tableViewX = tableView; static NSString *simpleTableIdentifier = @"SimpleTableCell"; SimpleTableCell *cell = (SimpleTableCell *)[tableView1 dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil]; cell = [nib objectAtIndex:0]; } dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ { NSString *imageURL = [NSString stringWithFormat: @"www.xyz.image.png"]; cell.thumbnailImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageURL]]]; }); 

Please help me with some sample code.

0
ios objective-c objective-c-blocks uiactivityindicatorview
source share
1 answer

You can use the AsyncImageView class files that will load the image synchronously and display an activity indicator when loading the image

You can download the AsyncImageView class files from the following link: https://www.dropbox.com/s/peazwjvky9fsjd7/Archive.zip

import AsyncImageView class into .m file

  #import "AsyncImageView.h" 

in a tableview cell in a path pointer method

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *simpleTableIdentifier = @"SimpleTableCell"; SimpleTableCell *cell = (SimpleTableCell *)[tableView1 dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil]; cell = [nib objectAtIndex:0]; } NSString *imageURL = [NSString stringWithFormat: @"www.xyz.image.png"]; AsyncImageView *async = [[AsyncImageView alloc]initWithFrame:CGRectMake(0, 0, width, height)]; [async loadImageFromURL:[NSURL URLWithString:imageURL]]; [cell.thumbnailImageView addSubview:async]; } 

try this problem.

+4
source share

All Articles