问题描述
- UITableView显示图片错误
-
使用GCD从网上加载图片到UITableViewCell
中,但是显示的图片不对。代码:
- (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 }
请帮忙看一下哪里的图片不对,谢谢。
解决方案
没看到你把图片赋值给 cell
不知道对不对?
时间: 2025-01-25 15:26:21