0

I followed the codes here https://stackoverflow.com/a/7212943/711837 to get me started to show an indicator my app trying to download images from a particular website. The scenario is:

i have a tableview with many custom cells, the custom cells has 2 labels and a imageview. i have a NSURL to download the contents that will fill up the labels and then a separate class that will download the images to be filled into the UIImageView. The code for the spinner and the downloading of images are:

resultArray = [[NSArray alloc] initWithArray:response];
[self downloadImageFromInternet:@"http://static.colourlovers.com/images/shapes/0/7/7090/50x50.png"];
//spinner for the download
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.frame = CGRectMake(0, 0, 24, 24);
custcell.accessoryView = spinner;
[spinner startAnimating];
///[spinner release];

[self.thetableView reloadData];

and then i call the [spinner stopAnimating] at the finish downloading method of the class but somehow, the spinners just don't animate, or appear for the matter! am i missing something? or is there somewhere i can refer to? my aim is to show the UIIndicatorView at the place of the UIImageView then after loading, the imageview takes over the same position and this is on every cell.

UPDATED added the methods

-(void) downloadImageFromInternet:(NSString*)urlToImage{
    // Create a instance of InternetImage
    asynchImage = [[DownloadThumb alloc] initWithUrl:urlToImage];

    // Start downloading the image with self as delegate receiver
    [asynchImage downloadImage:self];
}

-(void) internetImageReady:(DownloadThumb*)downloadedImage{ 
    // The image has been downloaded. Put the image into the UIImageView
    [arrayImg addObject:downloadedImage.Image];
    [spinner stopAnimating];
    [self.thetableView reloadData];
}

-(void)downloadImage:(id)delegate{
m_Delegate = delegate;

NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:ImageUrl] 
                                              cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60.0];
imageConnection = [[NSURLConnection alloc] initWithRequest:imageRequest delegate:self];

if(imageConnection)
{
    workInProgress = YES;
    m_ImageRequestData = [[NSMutableData data] retain];
}

}

Community
  • 1
  • 1
acvon
  • 161
  • 3
  • 6
  • 21
  • show your downloadImageFromInternet method...most probably you are calling it on main thread..which is blocking your UI to update – Shubhank Mar 06 '12 at 08:03
  • `- (void) downloadImageFromInternet:(NSString*) urlToImage { // Create a instance of InternetImage asynchImage = [[DownloadThumb alloc] initWithUrl:urlToImage]; // Start downloading the image with self as delegate receiver [asynchImage downloadImage:self]; } -(void) internetImageReady:(DownloadThumb*)downloadedImage { // The image has been downloaded. Put the image into the UIImageView [arrayImg addObject:downloadedImage.Image]; [spinner stopAnimating]; [self.thetableView reloadData]; } ` the latter is for when the data is downloaded – acvon Mar 06 '12 at 08:18
  • how do i format the lines! :S – acvon Mar 06 '12 at 08:18
  • add it to the question itself..as an edit.. that way it will be more clear.. – Shubhank Mar 06 '12 at 08:21
  • `[asynchImage downloadImage:self];` can you show this method? – Shubhank Mar 06 '12 at 08:52
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/8620/discussion-between-eddy-and-shubhank) – acvon Mar 07 '12 at 06:16

1 Answers1

0

You should really initiate the spinner when you create the cell.
Then you should check in cellForRowAtIndexPath if it should be visible or not.
Finally, when you need to display it, you can use [tableView reloadData] to display or remove it.

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • i initiated the spinner at CustomCell and now the spinner is turning, then in the `cellForRowAtIndexPath` where i set the image to the imageview in the cell and changed the alpha of the imageview to 1.0 (initiated as 0.0) and stopanimating for the spinner but it doesn't stop it... am i missing something? i hope you get what i'm trying to say – acvon Mar 06 '12 at 15:18