滚动表视图后出现图像(AFNetworking)

时间:2013-05-14 08:57:51

标签: iphone ios objective-c networking afnetworking

我正在使用AFNetworking从服务器下载图像,一切正常但图像不会出现,除非我滚动表视图。这是我的代码:

   - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

}

//configuring news feed
    dictionary = [newsFeed objectAtIndex:indexPath.row];
 //display thumbnails


    UIImageView *image = [[UIImageView alloc]init];
    [image setImageWithURL:[NSURL URLWithString:[dictionary objectForKey:@"image"]]placeholderImage:[UIImage imageNamed:NEWSAVATAR]];
    cell.imageView.image = [image.image imageScaledToSize:CGSizeMake(55, 55)];
    [cell setNeedsLayout];


    return cell;
}

2 个答案:

答案 0 :(得分:1)

试试这个

[ cell.imageView.image  setImageWithURL:[NSURL URLWithString:[dictionary objectForKey:@"image"]]placeholderImage:[UIImage imageNamed:NEWSAVATAR]];

答案 1 :(得分:0)

只有当该单元格可见时才会调用此委托方法,即您已滚动到单元格。如果您不希望发生这种情况,您必须调用Web服务并在本地保存所有图像,然后从本地文件夹中选择它。