I have a UITableView which becomes very laggy when during scrolling. My code snippet as follows:
In my “cell setupCell” I have a few customized items which I added to the cell contentview
-
1 X UIImageView
-
3 X UILabels
-
3 X buttons (subclass of UIControl)
My initial testing seems to point to the buttons causing the lag. I have some checks in the button class
I am not sure what exactly is the cause for the lag as these checks seemed to be very simple and basic operations. Anyone has any advise on what usually causes such lags?
EDIT: Add more code
I just want to add that the scrolling was smooth when I first started up the app, it became laggy and slow after I scrolled the table up and down multiple times. My code as follows:



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"];
I have checked instruments and they don’t seem to indicate much leakages for this part of the code

Can anyone advise what might be the cause of laggy after a series of scrolling?
Run it in Instruments, see where it’s spending its time when you scroll.