2

スクロール中に非常に遅くなるUITableViewがあります。私のコードスニペットは次のとおりです。

私の「cellsetupCell」には、セルのコンテンツビューに追加したいくつかのカスタマイズされたアイテムがあります

  • 1 X UIImageView

  • 3 X UILabels

  • 3つのXボタン(UIControlのサブクラス)

私の最初のテストでは、ラグの原因となっているボタンを指摘しているようです。ボタンクラスにチェックがあります

これらのチェックは非常に単純で基本的な操作であるように思われたため、ラグの原因が正確に何であるかはわかりません。誰かが通常そのような遅れを引き起こすものについて何かアドバイスがありますか?

編集:コードを追加

アプリを最初に起動したときはスクロールがスムーズでしたが、テーブルを何度も上下にスクロールすると、スクロールが遅くなりました。私のコードは次のとおりです。

ここに画像の説明を入力してください ここに画像の説明を入力してください ここに画像の説明を入力してください

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"];

機器をチェックしましたが、コードのこの部分に多くのリークがないようです。

ここに画像の説明を入力してください

一連のスクロール後の遅延の原因は何であるかを誰かにアドバイスできますか?

4

2 に答える 2

2

Instrumentsで実行し、スクロールしたときにどこで時間を費やしているかを確認します。

于 2011-07-01T01:49:34.490 に答える
1

原因が cornerRadius を設定したときであるかどうかを確認します (コメントしてください)。また、あなたのコードではわかりませんが、各行の要素にも影を追加している場合は、理由になる可能性があります。

于 2011-07-04T12:42:07.427 に答える