Ramu Pasupuleti
Ramu Pasupuleti

Reputation: 886

Wrong images are showing up in UITableviewcell

I am using GCD to load images from web into my UITableViewCell. But, wrong images are showing up.

Here is code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    UITableViewCell *cell = [self.newsTable dequeueReusableCellWithIdentifier:@"newsTableCell"];
    NSString *user = [usernames objectAtIndex:[indexPath row]];
    NSString *stat = [statistics objectAtIndex:[indexPath row]];
    NSString *imagePath = [appDelegate.URL stringByAppendingString:@"ImageName"];
    UIImageView *userImageView = (UIImageView *)[self.view viewWithTag:80];


        NSString *imagePath1 = [imagePath stringByAppendingString:[imagepaths objectAtIndex:[indexPath row]]];

        NSURL *url = [NSURL URLWithString:imagePath1];
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
    dispatch_async(queue, ^{
        NSData *data = [NSData dataWithContentsOfURL:url];
        UIImage *img = [[UIImage alloc] initWithData:data];
        userImageView.layer.cornerRadius = 5.0;
        userImageView.layer.masksToBounds = YES;
         dispatch_sync(dispatch_get_main_queue(), ^{
        [userImageView setImage:img];
         });
    });
 return cell
}

Please let me know, where I am going wrong.

Upvotes: 0

Views: 266

Answers (1)

Grzegorz Adam Hankiewicz
Grzegorz Adam Hankiewicz

Reputation: 7661

You are not using at all your cell variable, you are setting images on an UIImageView which comes from self.view. The images will never be set correctly on the cells of the table.

Upvotes: 1

Related Questions