0

I am new to IOS but I have made a small application that uses HJCache to display Images.

All fine, I found a way to Display an Image with HJCache, but I have a big Problem, I cannot unterstand how I display the Image to Show me the result when the Image was loaded.

My Actual Code is:

(I created the HJCache Object objMan - thumbs is a UIImageView *thumb

HJManagedImageV *asyncImage = [[[HJManagedImageV alloc] initWithFrame:CGRectMake(20,20,50,50)] autorelease];

asyncImage.url = [NSURL URLWithString:[thumbs_array objectAtIndex:thisItem]];
[objMan manage:asyncImage];
[objMan performSelectorOnMainThread:@selector(manage:) withObject:asyncImage waitUntilDone:YES];

[thumb setImage:asyncImage.image];  

The example Works, it will load the image but show it only after application restart. Does anyone have an idea?

JOM
  • 8,139
  • 6
  • 78
  • 111

2 Answers2

2

if u are loading images in tableview .I d do something like this instead of creating an UImageView ...

HJManagedImageV *asyncImage = [[[HJManagedImageV alloc]  
initWithFrame:CGRectMake(20,20,50,50)] autorelease];

asyncImage.url = [NSURL URLWithString:[thumbs_array objectAtIndex:indexpath.row]];
[objMan manage:asyncImage]; 
[cell addSubview:asyncImage];
mi=(HJManagedImageV *)[cell viewWithTag:999];
[mi clear];
kingston
  • 1,553
  • 4
  • 22
  • 42
1

Nikolas, are you open to alternate solutions?

If you are, I know of a very easy image loading library:

SDWebImage

Link: https://github.com/rs/SDWebImage

Simple to use, 1 line code to do what you want:

[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
                   placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

MWPhotoBrowser

Link: https://github.com/mwaterfall/MWPhotoBrowser

For displaying scrollable, pinch-zoom gallery automagically. MWPhotoBrowser uses SDWebImage in the back, so it's an extension of that library.

Zhang
  • 11,549
  • 7
  • 57
  • 87
  • Thanks for link..i just need to ask you that if i close the app and after some time start the app do i have to download all images again? – Swap-IOS-Android May 02 '13 at 14:13
  • These libraries have a caching mechanism on them. They download the images once and when you give the same URL, they will check their cache first and use that if it's already been downloaded once. So no, you don't have to download again, it'll all be loaded from cache. I do believe SDWebImage checks their cache after an interval (19 days I think) and update it if it needs to. – Zhang May 03 '13 at 07:40