Reputation: 3107
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;
}
Upvotes: 0
Views: 2246
Reputation: 6383
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.
Upvotes: 0
Reputation: 8383
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
Upvotes: 0
Reputation: 51374
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.
Upvotes: 4