Цель C: прокрутка UITableView становится запаздывающей - PullRequest
1 голос
/ 01 июля 2011

У меня есть UITableView, который становится очень запаздывающим при прокрутке. Мой фрагмент кода выглядит следующим образом:

В моем "cell setupCell" у меня есть несколько настроенных элементов, которые я добавил в ячейку contentview

  • 1 X UIImageView

  • 3 X UILabels

  • 3 кнопки X (подкласс UIControl)

Мое первоначальное тестирование указывает на кнопки, вызывающие задержку. У меня есть несколько проверок в классе кнопок

Я не уверен, что именно является причиной задержки, поскольку эти проверки казались очень простыми и основными операциями. Кто-нибудь есть какие-либо советы о том, что обычно вызывает такие лаги?

РЕДАКТИРОВАТЬ: Добавить больше код

Я просто хочу добавить, что прокрутка была плавной, когда я впервые запустил приложение, она стала медленной и медленной после прокрутки таблицы вверх и вниз несколько раз. Мой код выглядит следующим образом:

enter image description here enter image description here enter image description here

if (cell == nil)
{
    cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:PlaceholderCellIdentifier] autorelease];
    //Add like button
    UICustomButton *likeButton = [[UICustomButton alloc]init];
    likeButton.tag = 7;

    //Add comment button
    UICustomButton *commentButton = [[UICustomButton alloc]init];
    commentButton.tag = 8;

    //Add answer too button
    UICustomButton *answerButton = [[UICustomButton alloc]init];
    answerButton.tag = 9;

    [self.contentView addSubview:likeButton];
    [self.contentView addSubview:commentButton];
    [self.contentView addSubview:answerButton];

    [likeButton release];
    [commentButton release];
    [answerButton release];
}


//Set like button
UICustomButton *thisLikeButton = (UICustomButton *)[self.contentView viewWithTag:7];
[thisLikeButton setButtonWithAnswer:self.answerForCell buttonType:@"like" navcon:self.navcon andFrame:CGRectMake(CELL_TEXT_LEFT_MARGIN, totalCommentLabelHeight + CELL_SPACING*4, 45, CELL_BUTTON_HEIGHT)];
thisLikeButton.imageView.image = [UIImage imageNamed:@"heart.png"];


//Set comment button
UICustomButton *thisCommentButton = (UICustomButton *)[self.contentView viewWithTag:8];
 [thisCommentButton setButtonWithAnswer:self.answerForCell buttonType:@"comment" navcon:self.navcon andFrame:CGRectMake(CELL_TEXT_LEFT_MARGIN + 45 + 5, totalCommentLabelHeight + CELL_SPACING*4, 80, CELL_BUTTON_HEIGHT)];
thisCommentButton.imageView.image = [UIImage imageNamed:@"chat.png"];

//Set answer button
UICustomButton *thisAnswerButton = (UICustomButton *)[self.contentView viewWithTag:9];    
[thisAnswerButton setButtonWithAnswer:self.answerForCell buttonType:@"join in" navcon:self.navcon andFrame:CGRectMake(1.5*CELL_TEXT_LEFT_MARGIN + 45 + 5 + 80 + 5, totalCommentLabelHeight + CELL_SPACING*4, 60, CELL_BUTTON_HEIGHT)];
thisAnswerButton.imageView.image = [UIImage imageNamed:@"beer-mug_white.png"];

Я проверил приборы, и они, кажется, не указывают на значительные утечки для этой части кода

enter image description here

Кто-нибудь может посоветовать, что может быть причиной задержки после серии прокрутки?

Ответы [ 2 ]

2 голосов
/ 01 июля 2011

Запустите его в Instruments, посмотрите, где он проводит свое время при прокрутке.

1 голос
/ 04 июля 2011

Проверьте, если причина в том, когда вы устанавливаете cornerRadius (прокомментируйте это).Кроме того, я не вижу в вашем коде, но если вы также добавляете тень к элементам в каждой строке, это может быть причиной.

...