0

I have an UITableView which downloads its UITableViewCells images from a server.

I observed that the table scrolls very slowly.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"parallaxCell";
    JBParallaxCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    NSURL *imageURL = [NSURL URLWithString:[[news objectAtIndex:indexPath.row]objectForKey:@"Resim"]];
    NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
    UIImage *imageLoad = [[UIImage alloc] initWithData:imageData];


    cell.titleLabel.text = [[news objectAtIndex:indexPath.row]objectForKey:@"Adi"];
    cell.subtitleLabel.text = [[news objectAtIndex:indexPath.row]objectForKey:@"Resim"];
    cell.parallaxImage.image = imageLoad;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
SeRcCaN
  • 27
  • 4

3 Answers3

1

You are loading image file on main thread and this operation is slowing your scroll. Use UIImageView+AFNetworking.h from AFNetworking to speed up your app by async image loading. link https://github.com/AFNetworking/AFNetworking

0

Load the images asynchronously. It will help you :

Loading an image into UIImage asynchronously

Link

Community
  • 1
  • 1
Samkit Jain
  • 2,523
  • 16
  • 33
0

I use this Library which is just perfect

You just need to #import <SDWebImage/UIImageView+WebCache.h> to your project, and you can define also the placeholder when image is being downloaded with just this code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *MyIdentifier = @"MyIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:MyIdentifier] autorelease];
    }

    // Here we use the new provided setImageWithURL: method to load the web image
    [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;
}

It also cache downloaded images and gives you great performance.

Hope it will help you!

E-Riddie
  • 14,660
  • 7
  • 52
  • 74
  • I am glad it helps you! You can vote up this answer and setting it the correct answer by checking the tick! :) – E-Riddie Apr 22 '14 at 17:21