ios - 如何在TableView单元格中显示URL图像而不会卡住?

标签 ios objective-c xcode uitableview nsurl

我已经在URLImage单元格中显示了tableview的集合。在滚动单元格时卡住了。我曾经使用过SDWebImageManagerAFNetWorking这样的第三方。牢房卡住的机会永远不会少。

[imageVw setImageWithURL:[NSURL URLWithString:self.imgaeRecord.PreviewURl]placeholderImage:[UIImage imageNamed:@"default-thumbnail.jpg"]];


NSURL *url =[NSURL URLWithString:[self.MoviesListImage objectAtIndex:indexPath.row]];

SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadImageWithURL:url
                      options:0
                     progress:^(NSInteger receivedSize, NSInteger expectedSize) {
                        // progression tracking code
                     }
                    completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                    if (image) {
                        cell.recipeImageView.image = image;
                    }
                }];

最佳答案

在您的cellForRowAtIndexPath中

NSURL *url =[NSURL URLWithString:[self.MoviesListImage objectAtIndex:indexPath.row]];

SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadImageWithURL:url
                  options:0
                 progress:^(NSInteger receivedSize, NSInteger  expectedSize) {
                    // progression tracking code
           }
                completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                if (image) {
                   dispatch_async(dispatch_get_main_queue(), ^{
                   TableViewCellClass *updateCell = (id)[tableView cellForRowAtIndexPath:indexPath];
                   if (updateCell)
                     updateCell.yourImageView.image = image;
               });
           }
       }
}];
[task resume];

关于ios - 如何在TableView单元格中显示URL图像而不会卡住?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37815285/

相关文章:

iphone - 如何使 UIPickerView 具有 3 个可见行?

objective-c - 我必须在这里释放 OpenAL 上下文吗?

iphone - 初始化方法模式

ios - 针对不同构建配置的框架的 Xcode 项目文件引用路径

objective-c - UIViewAnimation 在 Objective-C 中不起作用

ios - 将嵌套字典写入 plist 时的类型问题 (Swift)

ios - 点击后退按钮时在 View 中显示消息

ios - 如何在 iOS 上获取多个目的地的预计到达时间?

objective-c - 未命名变量的内存管理

iphone - NSUserDefaults 值更改