Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6535855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:25:19+00:00 2026-05-25T10:25:19+00:00

I have a table like this: after several time drag to scroll table view

  • 0

I have a table like this:

before drag table

after several time drag to scroll table view it likes:

after drag table several times

I subclassed TTTableMessageItemCell and in subclassing class I added this:

- (void)prepareForReuse {
    [super prepareForReuse];
    _timeLabel.text = nil;
    _timeLabel = nil;
    self.commentTime = nil;
}

but not work…
what’s wrong?


- (void)layoutSubviews {


    [super layoutSubviews];
    self.backgroundColor = TTSTYLEVAR(tableCellColor1);


    CGSize userNameSize = [self.username sizeWithFont:TTSTYLEVAR(mySubtextFont)];


    if (self.username != nil && self.username.length){

        self.userNameLabel.text = self.username;


        self.userNameLabel.frame = CGRectMake(self.imageView2.right + 5.f, self.imageView2.top, userNameSize.width, userNameSize.height);
    }else{
        self.userNameLabel.frame = CGRectZero;

    }


self.titleLabel.width, captionSize.height);
    if (self.typeMessage != nil && self.typeMessage.length){

        self.typeMessageLabel.text = self.typeMessage;

        self.typeMessageLabel.frame = CGRectMake(self.imageView2.right + userNameSize.width + 5.f, kTableCellSmallMargin, self.contentView.width - self.imageView2.right - userNameSize.height - 5.f, userNameSize.height);
    }else{
        self.typeMessageLabel.frame = CGRectZero;
    }
}


- (UILabel*)userNameLabel{
    if (self.username != nil && self.username.length) {
        _userNameLabel = [[[UILabel alloc] init] autorelease] ;
        _userNameLabel.tag = 107;
        _userNameLabel.backgroundColor = [UIColor clearColor];


        _userNameLabel.font = TTSTYLEVAR(mySubtextFont);
        _userNameLabel.contentMode = UIViewContentModeLeft;
        //        _typeMessageLabel.enabled = NO;
        //        [_typeMessageLabel sizeToFit];
        [self.contentView addSubview:_userNameLabel];
        _userNameLabel =  (UILabel *)[self.contentView viewWithTag:107];
    }
    return _userNameLabel;
}

- (UILabel*)typeMessageLabel{
    if (self.typeMessage != nil && self.typeMessage.length) {
        _typeMessageLabel = [[[UILabel alloc] init] autorelease] ;
        _typeMessageLabel.tag = 105;
        _typeMessageLabel.backgroundColor = [UIColor clearColor];


        _typeMessageLabel.font = TTSTYLEVAR(mySubtextFont);
        _typeMessageLabel.contentMode = UIViewContentModeLeft;
//        _typeMessageLabel.enabled = NO;
//        [_typeMessageLabel sizeToFit];
        [self.contentView addSubview:_typeMessageLabel];
        _typeMessageLabel =  (UILabel *)[self.contentView viewWithTag:105];
    }
    return _typeMessageLabel;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:25:20+00:00Added an answer on May 25, 2026 at 10:25 am

    In your userNameLabel and typeMessageLabel methods, you are creating a new label every time it is called, adding it to the cell’s contentView, and you are not removing the old one ever.

    You need to make your cell subclass have iVars and create the labels only once, then just set the text when rendering the cell

    - (UILabel*)userNameLabel{
        if (!_userNameLabel) {
            _userNameLabel = [[[UILabel alloc] init] autorelease];
            _userNameLabel.tag = 107;
            _userNameLabel.backgroundColor = [UIColor clearColor];
            _userNameLabel.font = TTSTYLEVAR(mySubtextFont);
            _userNameLabel.contentMode = UIViewContentModeLeft;
            [self.contentView addSubview:_userNameLabel];
        }
        return _userNameLabel;
    }
    
    - (UILabel*)typeMessageLabel{
        if (!_typeMessageLabel) {
            _typeMessageLabel = [[[UILabel alloc] init] autorelease] ;
            _typeMessageLabel.tag = 105;
            _typeMessageLabel.backgroundColor = [UIColor clearColor];    
            _typeMessageLabel.font = TTSTYLEVAR(mySubtextFont);
            _typeMessageLabel.contentMode = UIViewContentModeLeft;
            [self.contentView addSubview:_typeMessageLabel];
        }
        return _typeMessageLabel;
    }
    

    Then, set your cell’s object in the correct place: the setObject: method, not the layoutSubviews method. The layoutSubviews method can be called multiple times per draw, and should only have the bare minimum positioning logic you need to layout the cells. Setting text, creating items and other high-cost functions should be down in setObject.

    - (void)setObject:(id)object {
        [super setObject:object];
        …
        (Do your other content-related setup here, not in layoutSubviews)
        …
        if ([self.username length])
            _userNameLabel.text = self.username;
        if ([self.typeMessage length])
            _typeMessageLabel.text = self.typeMessage;
    }
    

    Then in the prepareForReuse method, you set the text of these labels to be nil.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
I have a table like this: <table> <tfoot> <tr><td>footer</td></tr> </tfoot> <tbody> <tr><td>Body 1</td></tr> <tr><td>Body
I have a table like this (Oracle, 10) Account Bookdate Amount 1 20080101 100
I have a table like this: Application,Program,UsedObject It can have data like this: A,P1,ZZ
I have a Table like this one: |UserId | ContactID | ContactName --------------------------------------- |
I have a table like this: name code group john 12 smith 15 how
I have a table like this... CustomerID DBColumnName Data 1 FirstName Joe 1 MiddleName
i have a table like this one: -------------------------------- id | name -------------------------------- 1 |
I have two table like this table_CN (_id, name, phone, favorite, title) table_EN (_id,
I have a table like this (using wordpress) +---------+----------+------------+ | meta_id | meta_key |

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.