Search code examples
iphoneiosobjective-cafnetworkingafnetworking-2

AFNetworking UIImageView need scroll to load the images


I'm inserting images in a UITableViewCell with AFNetworking. The problem is that i need to scroll the table to see the images.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    Recipe *recipe = [self.fetchedResultsController objectAtIndexPath:indexPath];
    cell.textLabel.text = recipe.value;
    NSURL *url = [NSURL URLWithString:[BaseURLString stringByAppendingString:recipe.img]];
   [cell.imageView setImageWithURL:url];
    return cell;
}

Solution

  • There is such a method already implemented by AFNetworking in UIImageView+AFNetworking category.

    [imageView setImageWithURLRequest:request placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
        blockImageView.image = image;
    } failure:nil];
    

    Note that if you pass in nil in success the image is set to the imageview you call the method on. In my case imageView.

    So here i guess you can do reload data if you need.