2009-11-09 4 views
0

Je viens d'écrire une petite application lue à partir d'un flux de site et affichée dans UITableViewCell. J'utilise la cellule de vue personnalisée et mon UITableView est vissé dans le défilement comme il n'est pas très lisse en faisant défiler à l'envers. Une idée? Voici le code pour mon UITableViewCell,iPhone UITableViewCell performances lentes

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"CustomCell"; 

    CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     //  cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:nil]; 
     for(id currentObject in topLevelObjects) { 
      if([currentObject isKindOfClass:[UITableViewCell class]]) { 
       cell = (CustomCell *) currentObject; 
       break; 
      } 
     } 
    } 
    //MiceAppDelegate *AppDelegate = (MiceAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    if(dataArray != nil) { 
     // 
     //NSArray *promoArray = (NSArray *) promotions; 
     NSDictionary *datadict = [self.dataArray objectAtIndex:indexPath.row]; 

     NSString *url = [datadict objectForKey:@"imageUrl"]; 
     NSString *title = [datadict objectForKey:@"title"]; 
     NSString *description = [datadict objectForKey:@"description"]; 

     NSString *newAddressPartOfURL = [url stringByReplacingOccurrencesOfString:@" " withString:@"+"]; 

     //NSLog([url stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]); 

     NSURLResponse *urlResponse; 

     NSData *data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:newAddressPartOfURL]] returningResponse:&urlResponse error:nil]; 

     // Configure the cell. 
     UIImage *urlImage = [[UIImage alloc] initWithData:data]; 

     // NSLog(@"%i",[imageView.image topCapHeight]); 
     cell.title.text = title; 
     cell.description.text = description; 
     cell.image.image = urlImage; 
     [urlImage release]; 
    } 
    return cell; 
} 

Répondre

0

afaik la méthode dequeueReusableCellWithIdentifier est appelée comme les cellules se rincer etc. Construisez vos données/faire les demandes sur init, pas dans la création de cellules!

3

Faire des téléchargements synchrones au fur et à mesure que vos cellules sont dessinées provoquera certainement un défilement peu régulier. Vous pouvez essayer de remplacer ceux avec asynchronous appels, et en remplissant les données avec un objet générique pendant le téléchargement. Lorsque le téléchargement est terminé, appelez reloadData sur votre tableview.