ios表视图单元格按行索引顺序加载图像 [英] ios table view cell load images in the order of row index

查看:106
本文介绍了ios表视图单元格按行索引顺序加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在表格视图中配置单元格,我使用

 -(void)setImageWithURLRequest:(NSURLRequest *)urlRequest placeholderImage: (UIImage *)



AFNetworking 中的方法来加载单元格图像(



-中的web



中,用户不会卡住滚动。



----------



问题是每个图像都以随机顺序显示



因为此方法发送异步请求,



但是我希望它们一个接一个地显示,



例如第1行单元格中的图像必须在显示第0行单元格中的图像后显示,



就像加载可能是异步的(必须是)...



但是显示应该是同步的(按顺序!)



有一种简单的方法吗?



tha预先nks

解决方案

将图像名称存储在数组中,并在 cellForItemAtIndexPath()中访问它 > UITableView的方法。这样,您将获得正确的图像顺序。由于图像大小不同,您不应该一个接一个地显示图像(例如-如果图像大小以兆字节为单位,则加载将花费大量时间,该时间可用于加载其他图像)

  NSURL * photoURL = [NSURL URLWithString:[[array objectAtIndex:indexPath.row] valueForKey:@ Image]]; 
[cell.imgMyPhoto setImageWithURL:photoURL placeholderImage:null usingActivityIndi​​catorStyle:UIActivityIndi​​catorViewStyleGray];


Configuring cells in a table view, I use the

-(void)setImageWithURLRequest:(NSURLRequest *)urlRequest placeholderImage:(UIImage *)

method from AFNetworking to load cell images ( put it in cellForRowAtIndexPath ) from web

that users won't get stuck scrolling while it's loading.

----------

the question is that every image show up in random order

because this method sends asynchronous request,

yet I want them to be displayed one after another,

such as the image in row 1 cell must show up after image in row 0 cell is shown, and so on

it's like the loading could be asynchronous( and it must be)...

but the display should be synchronous (in order!)

is there an easy way to do this?

thanks in advance

解决方案

Store the name of the images in an array and access it in cellForItemAtIndexPath() method of the UITableView. By this way you will get the proper order of the images. You should not display images one after another because of different sizes of the images(for example - if the image size is in megabytes, it would take a lot of time to load, that time can be used to load another images)

NSURL *photoURL = [NSURL URLWithString:[[array objectAtIndex:indexPath.row] valueForKey:@"Image"]];
[cell.imgMyPhoto setImageWithURL:photoURL placeholderImage:nil usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

这篇关于ios表视图单元格按行索引顺序加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆