Tuesday, November 26, 2013

How to add activity indicator to the image in UITableView? http://stackoverflow.com/questions/15331079/how-to-add-activity-indicator-to-the-image-in-uitableview/15331306#15331306



I have created the Custom tableView and using custom tableView class in Other class to Show the tableView..

I am Loading the image from Server and displaying it in the tableViewRow.. each image is different in it..

On Screen only 7 out of 10 images will come, and when I scroll down the first 3 images are repeating for some time and when those images get load its showing proper images.. but initially till new images will come its showing old images, I want to put a activity indicator to show that the images are loading instead of old images..

I want to add activity Indicator in the place of image, till the image get load..

My code is...

  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 assist me with some sample code..

asked Mar 11 at 4:10
Raju
255
 
You can use asynchronous image view to achieve this .Because the image is showin like that as You are using the dequeueReusableCellWithIdentifier so make a diferent idefier or make cell is nill.. then u can achieve it –  08442 Mar 11 at 4:16
 
 
@08442 : How to use asynchronous image view? do you have any sample code from which i can understand it.. –  Raju Mar 11 at 4:26 
 
@bhargavi: do we need ASIHTTPRequest class to do this? –  Raju Mar 11 at 4:28
 
Cant i create the subView of image so that the activity indicator will work till the image is loaded? –  Raju Mar 11 at 4:30
show 1 more comment

You can use "AsyncImageView" class files it will load image synchronically and it shows the activity indicator while image loading

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

in .m file import AsyncImageView Class

   #import "AsyncImageView.h" 

in your tableview cell at indexpath 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 your problem will solve.

No comments:

Post a Comment