Lazy loading of image in tableview

前端 未结 5 1874
被撕碎了的回忆
被撕碎了的回忆 2021-01-25 09:57

Im trying to load the image of my uitableviewcells in lazy mode.

I\'m trying to do it in the simplest possible way, I saw a lot of examples but they were going further t

5条回答
  •  天涯浪人
    2021-01-25 10:32

    Try the following codes

      ......
      __block UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
      __block UIImage *img;
      dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    
            img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString: imageURL]]];
    
            dispatch_async(dispatch_get_main_queue(),^{
    
                cell.imageView.image = img;
    
                }
            });
    
    
        });
      ......
    

提交回复
热议问题