nicklockwood / AsyncImageView

[DEPRECATED]
http://charcoaldesign.co.uk/source/cocoa#asyncimageview
Other
906 stars 186 forks source link

use ImageURL after a certain process completes #4

Closed bolshas closed 12 years ago

bolshas commented 12 years ago

Hi,

I followed your suggestion to use AsyncImageView class for loading images on a background thread. However I came upon another issue. In my program, before I set the imageview, I have to call my web service via AsiHTTPRequest asynchronously, which pre-renders a certain image for me (this takes about 0.25 seconds per image).

So in carousel's viewForItemAtIndex I do this:

UIImageView *imgView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"noImageCarousel.png"]] autorelease]; [[Globals sharedGlobals] generateImageForIndex:index];

The second line starts the asynchronous request, which calls my web service, and receives a reply that the image has been created and is now stored on the server.

Then in the didfinishselector of the former request I do this:

UIImageView imgView = (UIImageView )[galleryCarousel.carousel itemViewAtIndex:[index intValue]]; [[AsyncImageLoader sharedLoader] cancelLoadingURL:imgView.imageURL]; imgView.imageURL = [self smallImageURLAtIndex:[index intValue]];

The problem is that imageURL method is never entered into and nothing is updated. I tried putting a breakpoint in the code of the setImageURL but it is never reached.

I don't know if this is an issue or my bad coding :)

nicklockwood commented 12 years ago

If you are already downloading your images asynchronously using ASI, you may not get any benefit from AsyncImageView, as doing that loading is it's main purpose.

Trying to get the item view from the carousel probably won't work because that will return nil if the item is offscreen as item views are only loaded when needed. That's probably why your imageURL method isn't being called - imgView is nil.

What you should do instead is call [carousel reloadItemAtIndex:animated] when your AsiHTTPRequest finishes downloading and processing your image. That will re-request the itemView from the datasource, and at that point you will have the image available, so you can set it directly on the view before returning it.

You will need to keep a cache of your downloaded images if you aren't already so that once they've been downloaded they are available to be requested by the carousel whenever it needs to display them.

Nick

On 6 Nov 2011, at 19:47, Andrius Bolsaitis wrote:

Hi,

I followed your suggestion to usi AsyncImageView class for loading images in background thread. However I came upon another issues. In my program, before I set the imageview, I have to call my web service via AsiHTTPRequest asynchronously, which pre-renders a certain image for me (this takes about 0.25 seconds per image).

So in carousel's viewForItemAtIndex I do this:

UIImageView *imgView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"noImageCarousel.png"]] autorelease]; [[Globals sharedGlobals] generateImageForIndex:index];

The second line starts the asynchronous request, which calls my web service, and receives a reply that the image has been created and is now stored on the server.

Then in the didfinishselector of the former request I do this:

UIImageView imgView = (UIImageView )[galleryCarousel.carousel itemViewAtIndex:[index intValue]]; [[AsyncImageLoader sharedLoader] cancelLoadingURL:imgView.imageURL]; imgView.imageURL = [self smallImageURLAtIndex:[index intValue]];

The problem is that imageURL method is never entered into and nothing is updated. I tried putting a breakpoint in the code of the setImageURL but it is never reached.

I don't know if this is an issue or my bad coding :)


Reply to this email directly or view it on GitHub: https://github.com/nicklockwood/AsyncImageView/issues/4

bolshas commented 12 years ago

Hi,

Thanks for your help. I fixed the code by modifying me web service.

Kind regards

Andrius