我正在使用GCD將圖像從網絡載入我的UITableViewCell
。但是,錯誤的圖像正在顯現。錯誤的圖像顯示在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
}
請讓我知道,我要去的地方錯了。
拉穆Pasupuleti請你詳細說明究竟是什麼解決了你的問題?因爲我擁有完全相同的問題 – Jonathan
@Jonathan,我正在使用標籤加載圖像。所以,我用自定義的UITableViewCell類替換了它。 –
哦好吧,但不會細胞也解決了這個問題? – Jonathan