Mithuzz
Mithuzz

Reputation: 1091

How to speed up the image loading-Facebook api-iphone?

Here I am creating an iPhone app using facebook api. I have loaded the friends list and their profile pictures into a table view. But now its running slowly. I want to speed up the loading of the pictures, how can I do that?

Here is my sample code:

- (void)request:(FBRequest*)request didLoad:(id)result { 
    NSArray* users = result; 
    for (int ndx = 0; ndx < [users count] ; ndx++)
    {
        NSDictionary* user = [users objectAtIndex:ndx]; 
        NSString* name = [user objectForKey:@"name"];
        NSString *imageName = [user objectForKey:@"pic_big"];
        [imageArray addObject:imageName];
        [friendsList addObject:name];
    }
}

In tableview delegate method:

imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString: [imageArray objectAtIndex:indexPath.row]]];
        image = [[UIImage alloc] initWithData:imageData];

        cell.imageView.image =image;

And also the picture sizes are different. Please help thanks

Upvotes: 1

Views: 598

Answers (1)

Aravindhan
Aravindhan

Reputation: 15628

By using the Lazyloading concept you can make it run fastly.
Just download this class for lazyloading.

It is very easy to impelement.

 #import "UIImageView+WebCache.h"  // Import this

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     ------------------ 
     ------------------
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]  placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

    cell.textLabel.text = @"My Text";
    return cell;
}

Upvotes: 1

Related Questions