How to place image from url to Imageview in iPhone

121 views Asked by At

In My application i am downlading image from url and showing it in uiimageview of uitableview cell.

Here I am getting problem is i am using Lazyloading but in mobile it is crashing because cache memory is full.So i am not getting any solution to resolve this.

If i am downloading in asynchronous way it is downloading for each cell in UItableView whenever i am scrolling the tableview,so it is taking very long time to download that,becuase the image i am getting from server is very big and resolution is very high so it is taking more time.

please help me any one i am trying but i am not getting any solution.I am very new to iphone development.Please some one give any suggestion.i used SdWebImage in lazyloading also so i am not getting any solution to my problem.

Thanks&Regards Sravya

3

There are 3 answers

0
Marko Hlebar On

You have to resize your images before caching them / displaying them on the image view. Regardless of which image format you are using, when the image is displayed in the view it is converted to a bitmap and the larger the image, the larger the memory footprint. Check the code here for some UIImage resizing categories which should help you achieve just that.

0
Satish Azad On

You have to manage your cashing from your own side. If you dont't want to do a lots of stuff the use AFnetworking Library

Use UIImageView Category : UIImageView Category

[imageViewObject setImageWithURL:YOUR_URL_FORIMAGE_HERE];

I hope this will helps you and easy.

0
Chitra Khatri On

Use this link:

https://github.com/nicklockwood/AsyncImageView

Download the code:

  1. Drag and Drop AsyncImageView.h and AsyncImageView.m in your project
  2. Use UITableView delegate methods

Here is Example code:

  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
      return [imageURLs count];
 }

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
    static NSString *CellIdentifier = @"Cell";

    #define IMAGE_VIEW_TAG 99

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
    //create new cell
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    //add AsyncImageView to cell
    AsyncImageView *imageView = [[AsyncImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 44.0f, 44.0f)];
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    imageView.clipsToBounds = YES;
    imageView.tag = IMAGE_VIEW_TAG;
    [cell addSubview:imageView];
    [imageView release];

    //common settings
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    cell.indentationWidth = 44.0f;
    cell.indentationLevel = 1;
}

//get image view
AsyncImageView *imageView = (AsyncImageView *)[cell viewWithTag:IMAGE_VIEW_TAG];

//cancel loading previous image for cell
[[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:imageView];

//load the image
imageView.imageURL = [imageURLs objectAtIndex:indexPath.row];

//display image path
cell.textLabel.text = [[[imageURLs objectAtIndex:indexPath.row] path] lastPathComponent];

return cell;
}

if you get any error in drag and drop classes of AsyncImageView click your prject->Build Phases->Compile Sources

in AsyncImageView.m write -fno-objc-arc

try it. hope helps you