目标C:UITableView滚动变为Laggy

时间:2011-07-01 00:35:27

标签: objective-c ios uitableview scroll lag

我有一个UITableView,在滚动时变得非常迟钝。我的代码片段如下:

在我的“cell setupCell”中,我有一些自定义项目,我已添加到单元格内容视图

  • 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 个答案:

答案 0 :(得分:2)

在乐器中运行它,看看它在滚动时花费的时间。

答案 1 :(得分:1)

检查原因是否设置了cornerRadius(注释)。此外,我无法在您的代码中看到,但如果您还在每行的元素上添加阴影,可能是一个原因。