2014-04-22 6 views
0

J'ai un UITableView qui télécharge ses images UITableViewCell depuis un serveur. J'ai observé que la table défile très lentement.UITableview avec images défilent très lentement

-(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; 
} 
+1

utilisez https://github.com/rs/SDWebImage pour charger vos images paresseusement. – limon

Répondre

1

Vous chargez le fichier image sur le fil principal et cette opération ralentit votre défilement. Utilisez UIImageView+AFNetworking.h de AFNetworking pour accélérer votre application par chargement d'image asynchrone. lien https://github.com/AFNetworking/AFNetworking

0

J'utilise cette bibliothèque qui est tout simplement parfait

Vous avez juste besoin de #import <SDWebImage/UIImageView+WebCache.h> à votre projet, et vous pouvez définir aussi l'espace réservé lorsque l'image est en downloa ded avec juste ce 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; 
} 

Il cache également des images téléchargées et vous donne de grandes performances.

J'espère que ça va vous aider!

+0

Merci Erid Works Parfait – SeRcCaN

+0

Je suis heureux que cela vous aide! Vous pouvez voter pour cette réponse et définir la bonne réponse en cochant la case! :) – EridB

Questions connexes