2012-03-26 10 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; 
    } 
} 
関連する問題