keep on you
keep on you

Reputation: 310

Download an asynchronous multiple images in UITableViewView?

How can i download an asynchronous multiple images in the UITableView using ASIHttpRequest or something useful?

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
      ..........

      // Creation
      UIImageView *avatar;
      UILabel *content; 

      // Tag the IBOutlets
      avatar = (UIImageView*)[cell viewWithTag:14];
      content = (UILabel*)[cell.contentView viewWithTag:4];

      // Field
      avatar.image = image
      content.text = entryReviewtableView.content;
 }

Upvotes: 2

Views: 1292

Answers (3)

PeyloW
PeyloW

Reputation: 36752

No need to introduce a dependency to a whole framework such as ASIHTTPRequest just to download one image, when you can do it a few easy lines of code using GCD:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    NSData *imageDate = [NSData dataWithContentsOfURL:imageURL];
    UIImage *image = [UIImage imageWithData:imageData];
    dispatch_async(dispatch_get_main_queue(), ^{
        avatar.image = image;
    });
});

This is asynchronous and all the goodness. But in a few lines of code you can write, understand, bug-fix, extend and maintain yourself.

Upvotes: 6

Hiren
Hiren

Reputation: 12780

    UIImageView *imgV=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 748)];

    ASIHTTPRequest *req=[ASIHTTPRequest requestWithURL:[NSURL URLWithString:[Array objectAtIndex:indexPath.row]]];
    [req setUsername:[NSString stringWithFormat:@"%i",i]];
    [req setUserInfo:[NSDictionary dictionaryWithObjectsAndKeys:imgV,@"imgV",nil]];
    [req setDelegate:self];
    [req startAsynchronous];
    //[imgV setContentMode:UIViewContentModeScaleToFill];
    [imgV setContentMode:UIViewContentModeScaleAspectFit];
    //[imgV setClipsToBounds:YES];
    [imgV setTag:kTagImageViewInScrollView];
    [cell addSubview:imgV];

- (void)requestFinished:(ASIHTTPRequest )request { [(UIImageView)[[request userInfo] valueForKey:@"imgV"] setImage:[UIImage imageWithData:[request responseData]]];

[(UIActivityIndicatorView*) [(UIScrollView*) [scr viewWithTag:([[request username] intValue]+1)] viewWithTag:kActTag] removeFromSuperview];

}

Upvotes: 0

MinuMaster
MinuMaster

Reputation: 1457

You can be use the asynchronous image view instead of the default image view. for reference you can visit tutorial Here.

Upvotes: 0

Related Questions