objective-c - objective-c : UITableView Scrolling becomes Laggy

标签 objective-c ios uitableview scroll lag

我有一个 UITableView,在滚动过程中变得非常滞后。我的代码片段如下:

在我的“单元设置单元”中,我有一些自定义项目添加到单元内容 View 中

  • 1 个 UIImageView

  • 3 个 UILabel

  • 3 个按钮(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

谁能告诉我在一系列滚动后可能出现延迟的原因是什么?

最佳答案

在 Instruments 中运行它,当您滚动时查看它把时间花在哪里。

关于objective-c - objective-c : UITableView Scrolling becomes Laggy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6542535/

相关文章:

ios - 如何在 iPhone 笔记应用程序中添加和删除笔记

ios - 将数据存储在闭包的变量中

c#-4.0 - 使用 Monotouch 在 UITableViewCell 中绘制网格

ios - Swift xcode 错误 : Value of type 'DetailViewController' has no member 'Animal'

ios - 如何在 Objective-C 中将图像从主 viewController 设置到 tableView 单元格?

objective-c - NSMutableArray 对对象进行排序

ios - SwiftUI:VStack/HStack/ZStack 拖动手势不起作用

ios - 填充整个屏幕宽度并且一次仅滚动一个的集合单元格?

ios - 在 tableView 中重新加载后保持滚动位置

ios - 我可以只使用 3x 的 images.xcassets 吗?