UITableviewcell中显示了错误的图像 [英] Wrong images are showing up in UITableviewcell

查看:51
本文介绍了UITableviewcell中显示了错误的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GCD将来自Web的图像加载到我的UITableViewCell中.但是,出现了错误的图像.

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

这是代码:

- (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.

推荐答案

您根本没有使用cell变量,而是在来自self.viewUIImageView上设置了图像.永远不会在表格的单元格上正确设置图像.

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.

这篇关于UITableviewcell中显示了错误的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆