IOS:LazyLoad图片来自Json

时间:2012-10-11 03:32:06

标签: objective-c ios json lazy-loading nsjsonserialization

我是这种编程语言的新手...我尝试从一些服务器中消耗json,成功消耗所有信息后,现在我有问题将“lazyload”图像显示到tableviewcell

我使用AsyncImageView来实现它,而这里是我的代码

-(UITableViewCell *)tableView :(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    NetraCell *cell =(NetraCell *)[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell==nil){
        cell=[[NetraCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];

        //common settings
        cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
        cell.imageView.frame = CGRectMake(0.0f, 0.0f, 44.0f, 44.0f);
        cell.imageView.clipsToBounds = YES;

        ///get url image from url
        //NSString *path=[[[Deals_array objectAtIndex:indexPath.row] objectForKey:@"image"]objectForKey:@"thumbnail"];

        ////convert image into NSDATA
    //  NSData* imageData = [NSData dataWithContentsOfURL: [NSURL URLWithString: path]];
        ////read NSData Image
    //  UIImage* image = [UIImage imageWithData: imageData];
        //////set rounded imager with NetraImage

    //  image=[ImageManipulator makeRoundCornerImage:image : 30 : 30];

        ////show image into UItableviewCell
    //  cell.imageView.image=image;

    }
    else{
        //cancel loading previous image for cell
        [[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:cell.imageView];
    }
    cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"];
    cell.imageView.imageURL = [[[imageURLs objectAtIndex:indexPath.row]objectForKey:@"image"]objectForKey:@"thumbnail"];

    NSString *price=[[[somearray objectAtIndex:indexPath.row] objectForKey:@"price"]objectForKey:@"formatted"];
    ///call image from JSOn


    ///draw to tableviewcell
    if(price!=NULL){
        cell.detailTextLabel.text= [[[Deals_array objectAtIndex:indexPath.row] objectForKey:@"price"]objectForKey:@"formatted"]; //1 draw the price
        //[cell release]
    }
    else{
    cell.detailTextLabel.text= @"Call";

    }
    //draw headline
    cell.textLabel.text=[[Deals_array objectAtIndex:indexPath.row] objectForKey:@"headline"];
    ///draw image


         [UIApplication sharedApplication].networkActivityIndicatorVisible=NO;
    return  cell;
}

这条线是我的影像之路

//NSString *path=[[[Deals_array objectAtIndex:indexPath.row] objectForKey:@"image"]objectForKey:@"thumbnail"];

这是将pic分配到uitableviewcell

的默认方法
cell.imageView.imageURL = [imageURLs objectAtIndex:indexPath.row];

但是当我尝试这种方法时

cell.imageView.imageURL = [[[imageURLs objectAtIndex:indexPath.row]objectForKey:@"image"]objectForKey:@"thumbnail"];

错误,主要问题是

  1. 为什么错误?是我的远程图像路径错了吗?或者我的方法错了
  2. 需要你的帮助:)非常感谢

1 个答案:

答案 0 :(得分:1)

一旦检查您是否在代码中为单元格图像url分配了适当的图像,[[[imageURLs objectAtIndex:indexPath.row] objectForKey:@“image”] objectForKey:@“thumbnail”],然后通过这可能对你有所帮助   lazy loading of images in UITableView cell