2012-03-26 81 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 2012-03-26 11:28:24

+0

Whithin的截面。 – Sneezy 2012-03-26 12:15:19

+0

我找到了解決辦法 – Sneezy 2012-03-26 14:20:06

回答

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; 
    } 
} 
相關問題