ASIHTTP 请求不工作
我的 cellForIndexPath 中有以下代码,但图片的顺序不正确:
NSURL *url = [NSURL URLWithString:[self.picturesArray objectAtIndex:indexPath.row]];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
NSData *responseData = [request responseData];
cell.imageView.image = [UIImage imageWithData:responseData];;
}];
[request setFailedBlock:^{
NSError *error = [request error];
}];
[request startAsynchronous];
I have the following code in my cellForIndexPath but the pics are not in the right order:
NSURL *url = [NSURL URLWithString:[self.picturesArray objectAtIndex:indexPath.row]];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
NSData *responseData = [request responseData];
cell.imageView.image = [UIImage imageWithData:responseData];;
}];
[request setFailedBlock:^{
NSError *error = [request error];
}];
[request startAsynchronous];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
[那么我会改变我的答案,因为你完全改变了问题。 :-) ]
那么...图像在错误的单元格中?
电池的重复使用可能是问题所在。您正在启动一个异步进程来加载单元格的图像。如果该单元格滚动离开屏幕,则该单元格对象可能会被另一个进入视图的单元格重新使用。同时,正在加载的第一个图像将继续加载,除非您注意到单元已被重新使用和/或取消先前的加载。
滚动时图像的显示顺序是否错误?或者,如果您只是启动应用程序而不滚动表格,是否会发生这种情况?
[I will change my answer then, since you changed the question entirely. :-) ]
So... images in the wrong cells?
Cell re-use is likely the issue. You're starting an asynchronous process to load an image for a cell. If that cell scrolls off the screen, that cell object will likely be re-used for another cell that comes into view. Meanwhile, the first image being loaded will continue to be loaded, unless you can notice that the cell has been re-used and/or cancel the previous load.
Are the images appearing in the wrong order when you scroll? Or, does this happen if you just launch the app and do not scroll the table?