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 に答える