Objective c 为什么Grand Central Dispatch仅在点击时才显示单元格中的图像?

Objective c 为什么Grand Central Dispatch仅在点击时才显示单元格中的图像?,objective-c,grand-central-dispatch,Objective C,Grand Central Dispatch,我有点奇怪。tableview通过其API加载flickr照片。加载视图后,它会创建一个名称和photoURL数组。然后在cFRAIP tableview方法中,它使用它们来设置单元格值 我决定和GCD一起玩,结果是: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{UITableViewCell *cell = [[[UITableVie

我有点奇怪。tableview通过其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;}
但我得到的是一个表格视图,每个单元格中都有照片名称,而没有图片。只有当我轻触单元格时,图片才会加载。为什么会发生这种情况?


哦,我明白了,你有一个小的打字错误:

dispatch_async(kfetchQueue, ^{
    //NSData *imageData = [NSData dataWithContentsOfURL:[photoURLs objectAtIndex:indexPath.row]];
    dispatch_async(dispatch_get_main_queue(), ^{
        //cell.imageView.image = [UIImage imageWithData:imageData];
    });    //<-------right here :)  thx!
});
dispatch\u async(kfetchQueue^{
//NSData*imageData=[NSData datawithcontentsofull:[photoURLs objectAtIndex:indexath.row]];
dispatch\u async(dispatch\u get\u main\u queue()^{
//cell.imageView.image=[UIImage imageWithData:imageData];

});//好的,但是你能解释一下为什么它是这样工作的,直到我点击它,图像才会显示出来吗?顺便说一句,由于某种原因,上面的代码不起作用。它扔掉了我的cFRAIP方法外壳。我在结束时得到了一个预期的“')”;'抱歉,输入错误,刚刚修复。它需要cell setNeedsLayout:)
dispatch_async(kfetchQueue, ^{
    //NSData *imageData = [NSData dataWithContentsOfURL:[photoURLs objectAtIndex:indexPath.row]];
    dispatch_async(dispatch_get_main_queue(), ^{
        //cell.imageView.image = [UIImage imageWithData:imageData];
    });    //<-------right here :)  thx!
});