2014-03-25 2 views
0

은 다음 tableView:cellForRowAtIndexPath:의 내 구현 될 때 . 처음에는 뷰가로드되고 셀이 채워지면 모든 것이 예상대로 진행됩니다. 이미지가 다운로드되어 셀에 배치됩니다. 문제는 내가 테이블 뷰를 스크롤하기 시작할 때입니다. NSLog는 (null)을 보여줍니다. 나는 왜 tableCell 객체가 null인지를 알 수 없다.있는 UITableViewCell 블록 내부에 전무로 돌아

추신 : 나는 거의 동일한 example from Apple을 수행 한 후 예제를 작성했습니다. 또한 확인했는데 self.tableView도 아니고 indexPath도 블록 안에 없습니다. 블록은 비동기

답변

0

, 당신은 블록 밖에서 세포를 생성하고 단지 내부 이미지 설정해야합니다 : 동일한 방법에서`cellForRowAtIndexPath` 부르는 것을 들어

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    BSProductCell *cell = [tableView dequeueReusableCellWithIdentifier:BSProductCellIdentifier]; 
    if(cell==nil){ 
     cell = [[BSProductCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:BSProductCellIdentifier]; 
    } 

    cell.productImageView.image = [UIImage imageNamed:@"Placeholder"]; 

    [[BSImageLoader sharedInstance] getImageWithURL:self.dataSourceArray[indexPath.row] withCompletionBlock:^(UIImage *image, BOOL fromCache, NSString *error){ 

     //Here you check that the cell is still displayed 
     if([tableView cellForRowAtIndexPath:indexPath]){ 
      [cell.productImageView setImage:image]; 
      NSLog(@"%@", cell); 
     } 
    }]; 
    return cell; 
} 
+0

를? – sage444

+0

내 코드가 잘못되었습니다. – streem

+0

훨씬 좋음 – sage444