我有一些有趣的事情发生。表格视图通过其 API 加载 flickr 照片。加载视图后,它会创建一个名称和 photoURL 数组。然后在 cFRAIP tableview 方法中,它使用它们来设置单元格值。
我决定与 GCD 一起玩,结果是这样的:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell Identifier"] autorelease];
cell.textLabel.text = [photoNames objectAtIndex:indexPath.row];
dispatch_async(kfetchQueue, ^{
NSData *imageData = [NSData dataWithContentsOfURL:[photoURLs objectAtIndex:indexPath.row]];
cell.imageView.image = [UIImage imageWithData:imageData];
});
return cell;}
但我得到的是一个表格视图,每个单元格中都有照片名称,没有图片。图片仅在我点击单元格时加载。为什么会这样?