0

Hello I am trying to get profile image of facebook user in Table's cell.image. But It slows down Scrolling of Table view.Then I used Asynchronous loading of image link But i am confused how could I use this in my Table's method

    - (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] autorelease];
        }

        cell.textLabel.font = [ UIFont fontWithName:@"Arial" size:10.0];
        cell.textLabel.numberOfLines = 0;

        cell.textLabel.text = [NSString stringWithFormat:@"%@",[(Facebook *)[dummyArray objectAtIndex:indexPath.row] sender]];

        cell.detailTextLabel.text =[NSString stringWithFormat:@"%@",[(Facebook *)[dummyArray objectAtIndex:indexPath.row] post]];

        NSString *get_string = [NSString stringWithFormat:@"%@/picture",[(Facebook *)[dummyArray objectAtIndex:indexPath.row]senderId]];

        AsynchronousImageView *image = [[AsynchronousImageview alloc]init];
[image loadImagewithUrlString:getString];

        FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:get_string withGetVars:nil];

        UIImageView *image_view = [[UIImageView alloc] initWithImage:fb_graph_response.imageResponse];


        cell.imageView.image = image_view.image;



        [image_view release];


        return cell;
    }
EmptyStack
  • 51,274
  • 23
  • 147
  • 178
iProgrammer
  • 3,099
  • 3
  • 33
  • 59

3 Answers3

4

Its slows down because you are setting the image every time the cellForRowAtIndexPath: is called. Add the image to the cell's imageView only inside the if (cell == nil) block. Then you will see the improvement in scrolling.

EmptyStack
  • 51,274
  • 23
  • 147
  • 178
0
    AsynchronousImageView *image = [[AsynchronousImageview alloc]init];
    [image loadImagewithUrlString:getString];

    FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:get_string withGetVars:nil];

    UIImageView *image_view = [[UIImageView alloc] initWithImage:fb_graph_response.imageResponse];


    cell.imageView.image = image_view.image;

This code is creating the described problem ..... try this approch ... once any image is downloaded save it in any temp folder in document directory(make name of ur image such that you can identify each of them uniquely)....and when you have to configure the cell just take the image form tha temp folder every time the method celForRowAtIndexPath is called .... dont use

   UIImageView *image_view = [[UIImageView alloc];

This make no sence here as you are not using it (you are just using its .image property) .... also if possible collect all you data in viewDidLoad in that way you can further improve the performance

Amit Singh
  • 8,383
  • 4
  • 28
  • 31
0

Are you sure it's the async image causing problems? Comment the async image part, and see maybe it's the FbGraphResponse part the actual cause.

I see that you're creating an image each time for the graph response and this can cause a slow-down.

Andrei Stanescu
  • 6,353
  • 4
  • 35
  • 64
  • No async image is not causing prob ..Actually because of creating image everytime it slows down the tableview scrolling so I thought to use Async. image example. and I was not getting how to use this, thats y I asked question here but It is working fine with simon's suggestion – iProgrammer Jun 20 '11 at 08:32