2016-08-27 1 views
0

tableView가 있습니다. 배열 (cellMap)에서 데이터를 가져옵니다. viewDidLoad에 데이터가 배열에 추가됩니다.백그라운드에 이미지를로드하십시오.

CellModel *model = self.cellMap[indexPath.row]; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:configurator.identifier forIndexPath:indexPath]; 

cell.title = model.title; 
cell.price = model.price; 
cell.image = model.image; 

return cell; 

방법 화상 부하에 대한 백그라운드에서 : 데이터가 어레이로부터 촬영 cellForRowAtIndexPath 방법에

[self.cellMap addObject:[CellModel initWithTitle:title 
              price:price 
              image:getProductImageByImgURL:url 
]; 

- (UIImage *)getProductImageByImgURL:(NSString *)url { 
    __weak typeof(self)weakSelf = self; 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
     __strong typeof(self)strongSelf = weakSelf; 

     strongSelf.productImage = [UIImage loadImage:url]; 
    }); 
    return self.productImage; 
} 

어디 self.productImage@property (strong, nonatomic) UIImage *productImage;

결과 - 모든 셀에는 마지막으로로드 된 이미지가 있습니다. 문제가 무엇입니까?

답변

0

나는이에서 문제 결과,

strongSelf.productImage = [UIImage loadImage:url]; 

당신은 임시 변수를 사용하려고 할 수 있다고 생각합니다. 그리고 그것을 만드십시오,

UIImage * tempImage = [UIImage loadImage:url]; 
+0

Not working .. 8 ( – Gikas