2

我是这种编程语言的新手...我尝试从一些服务器使用 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. 为什么会出错?那是我的远程图像路径错误吗?或者我的方法不对

需要你的帮助:)非常感谢

4

1 回答 1

1

一旦检查您是否在代码中为单元格图像 url 分配了适当的 imageurl,[[[imageURLs objectAtIndex:indexPath.row]objectForKey:@"image"]objectForKey:@"thumbnail"],然后通过它可以帮助您 在 UITableView 单元格中延迟加载图像

于 2012-10-11T12:11:19.227 回答