2012-03-26 6 views
0
#import "UIImageView+AFNetworking.h" 

테이블에서 스크롤하면. 세포가 장소를 바꿉니다. 첫 번째 세포가 무엇인지 알지 못하는 것 같습니다.테이블에서 스크롤하면 셀이 바뀝니다

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier]; 

    if(indexPath.section == 0) 
    { 
     Recipe *dish = [_recipes objectAtIndex:indexPath.row]; 
     cell.textLabel.text = dish.user; 
     cell.imageView.image = _imageView.image; 
     return cell; 
    } 
    else if (indexPath.section == 1 || indexPath.section == 2) 
    { 
     Recipe *dish = [_recipesExtra objectAtIndex:indexPath.row]; 
     cell.textLabel.text = dish.title; 
     [cell.imageView setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString: dish.url]] 
           placeholderImage:nil 
           success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { 
              [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; 
             } 
           failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) { 
             }]; 
     return cell; 
    } 
    else 
    { 
     return nil; 
    } 


} 

내 실수는 reloadRowsAtIndexPaths에 있지만 그 문제를 해결하는 방법을 모르겠다.

+1

장소를 변경하는 셀은 무엇입니까? 섹션 내 또는 섹션 간? 특정 섹션? – jrturton

+0

섹션이 있습니다. – Sneezy

+0

해결책을 찾았습니다 – Sneezy

답변

1

이미지를 저장할 수있는 곳을 새로 만들었습니다. 다시로드 할 때 단순히 "저장 한"이미지를 가져와 인터넷에서 이미지를로드 할 필요가 없습니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier]; 

    if(indexPath.section == 0) 
    { 
     Recipe *dish = [_recipes objectAtIndex:indexPath.row]; 
     cell.textLabel.text = dish.user; 
     cell.imageView.image = _imageView.image; 
     return cell; 
    } 
    else if (indexPath.section == 1 || indexPath.section == 2) 
    { 
     Recipe *dish = [_recipesExtra objectAtIndex:indexPath.row]; 
     cell.textLabel.text = dish.title; 
     if (dish.image) { 
      cell.imageView.image = dish.image; 
     } 
     else 
     { 
      [cell.imageView setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString: dish.url]] 
            placeholderImage:nil 
              success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { 
               dish.image = image; 
               [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; 
              } 
              failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) { 
              }]; 

     } 

     return cell; 
    } 
    else 
    { 
     return nil; 
    } 
} 
관련 문제