ASIHTTP 请求不工作

发布于 2024-12-04 16:08:50 字数 476 浏览 2 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独享拥抱 2024-12-11 16:08:50

[那么我会改变我的答案,因为你完全改变了问题。 :-) ]

那么...图像在错误的单元格中?

电池的重复使用可能是问题所在。您正在启动一个异步进程来加载单元格的图像。如果该单元格滚动离开屏幕,则该单元格对象可能会被另一个进入视图的单元格重新使用。同时,正在加载的第一个图像将继续加载,除非您注意到单元已被重新使用和/或取消先前的加载。

滚动时图像的显示顺序是否错误?或者,如果您只是启动应用程序而不滚动表格,是否会发生这种情况?

[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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文