2012-03-26 78 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; 
    } 
} 
相关问题