2010-09-14 4 views
0

J'ai une cellule UITableView personnalisée qui porte une image, et un titre. J'ai utilisé l'exemple de défilement rapide de ABTableViewCell d'atebits.Grande UIImage drawinrect extrêmement lent sur la sélection

Il me semble que lorsque je sélectionne la première rangée (qui est ma rangée avec la plus grande image), il faut beaucoup de temps pour mettre la rangée en surbrillance, puis pousser le nouveau contrôleur de vue. Cependant, lorsque je sélectionne l'une des autres lignes, avec des images beaucoup plus petites, c'est presque instantané. J'ai essayé de dessiner l'image en utilisant CGContextDrawImage et drawInRect, mais les deux produisent les mêmes résultats.

- (void)drawContentView:(CGRect)r highlighted:(BOOL)highlighted { 
if ([type isEqualToString:@"first"]) { 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    UIColor *backgroundColor = [UIColor blackColor]; 
    UIColor *textColor = [UIColor whiteColor]; 
    UIColor *textBackgroundColor = [[UIColor alloc] initWithWhite:0 alpha:.5]; 
    UIColor *highlightColor; 
    if (highlighted) { 
    backgroundColor = [UIColor clearColor]; 
    textColor = [UIColor blueColor]; 
    highlightColor = [[UIColor alloc] initWithWhite:0 alpha:.3]; 
    } else { 
    highlightColor = [UIColor clearColor]; 
    } 

    [backgroundColor set]; 
    CGContextFillRect(context, r); 
    [self.picture drawInRect:CGRectMake(0.0, 0.0, 320, 225)]; 
    [textBackgroundColor set]; 
    CGContextFillRect(context, CGRectMake(0, 170, 320, 55)); 
    [textColor set]; 

    [self.title drawInRect:CGRectMake(5, 170, 320, 55) withFont:firstHeadlineFont lineBreakMode:UILineBreakModeWordWrap]; 
    [highlightColor set]; 
    CGContextFillRect(context, r); 
} else { 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    UIColor *backgroundColor = [UIColor blackColor]; 
    UIColor *textColor = [UIColor blueColor]; 

    if (highlighted) { 
    backgroundColor = [UIColor clearColor]; 
    textColor = [UIColor whiteColor]; 
    } 
    [backgroundColor set]; 
    CGContextFillRect(context, r); 

    CGPoint p; 
    p.x = 0; 
    p.y = 0; 
    [self.picture drawInRect:CGRectMake(0.0, 0.0, 44, 44)]; 

    [textColor set]; 
    p.x += 44 + 6; // space between words 
    [self.title drawAtPoint:p withFont:[UIFont systemFontOfSize:20]]; 
} 
} 

EDIT: Que dois-je peux faire pour accélérer ce? Je cache l'image et la lis aussi.

Répondre

0

Je me suis rendu compte que j'utilisais une très très grande version de l'image pour ma première rangée, j'ai pu la réduire avant de la retirer du serveur web et cette performance considérablement améliorée. NOTE: vérifiez vos dimensions ne sont pas énormes. IE: 2184x1456 hahah

Questions connexes