2013-12-11 66 views
0

在我的应用程序中,我下载来自url的图像并在uitableview单元格的uiimageview中显示它。如何将URL中的图像从URL下载到Imageview中

这里我得到的问题是我使用Lazyloading但在移动它崩溃,因为缓存内存已满。所以我没有得到任何解决方案来解决这个问题。

如果我以异步方式下载,每当我滚动tableview时,它都会下载到UItableView中的每个单元,因此下载它需要很长时间,因为我从服务器获得的图像非常大并且分辨率非常高,所以需要更多的时间。

请帮助我任何一个我想,但我没有得到任何解决方案。我是非常新的iphone开发。请给我一些建议。我在懒惰加载也使用SdWebImage所以我没有得到任何解决方案,我的问题。

感谢&问候 Sravya

回答

0

你必须从自己的侧管理您兑现。 如果dont't想做很多东西使用AFnetworking Library

使用的UIImageView类别:UIImageView Category

[imageViewObject setImageWithURL:YOUR_URL_FORIMAGE_HERE]; 

我希望这将有助于你和容易。

0

您必须先调整图像大小,然后再缓存图像或在图像视图上显示图像。 无论使用哪种图像格式,图像在视图中显示时都会转换为位图,图像越大,则占用的内存就越大。检查代码here的某些UIImage调整大小类别应该可以帮助您实现这一目标。

0

使用此链接:

https://github.com/nicklockwood/AsyncImageView

下载代码:

  1. 将在您的项目,请AsyncImageView.hAsyncImageView.m
  2. 使用的UITableView委托方法

这里是示例代码:

- (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; 
} 

如果你在拖动任何错误和下降AsyncImageView类单击prject->构建Phases->编译源代码

在AsyncImageView.m写-fno-objc弧

试试吧。希望能帮到你