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 7527187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:03:20+00:00 2026-05-30T04:03:20+00:00

I got app with UITableView. There is UILabel in each UITableViewCell. I add labels

  • 0

I got app with UITableView.

There is UILabel in each UITableViewCell. I add labels in this way:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  //look at the upd
}

But when i try to reload data in this table with some other information, old infromation (old labels) dont disappear, but still on cells.

It’s look like this: …

How should i organized adding UILabels?

UPD

I correct code in this way:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Recent Dream";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        UILabel *textLabel = [[UILabel alloc] init];
        textLabel.frame = CGRectMake(10, 0, self.view.frame.size.width -110, 48);
        textLabel.backgroundColor = [UIColor clearColor];
        textLabel.font = [UIFont boldSystemFontOfSize:16];
        [textLabel setTag:(int)indexPath];
        [cell.contentView addSubview:textLabel];


    }
    // Configure the cell...

    Dream *tempDream = [self.dreams objectAtIndex:indexPath.row];

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"MM/dd/yyyy"];

    //Optionally for time zone converstions
    [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"..."]];

    NSString *stringFromDate = [formatter stringFromDate:tempDream.dateAdd];

    UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bodyWrapper.png"]];

    cell.contentView.backgroundColor = background;

    UILabel *textLabel = (UILabel *)[cell viewWithTag:(int)indexPath];
    textLabel.text = tempDream.title;

    NSLog(@"%@",tempDream.title);
    NSLog(@"%@",textLabel.text);

    cell.textLabel.text = @"";
    cell.detailTextLabel.text = stringFromDate;

    return cell;
}

And output look like this:

2012-02-20 15:58:10.512 DreamerIOS[3037:10403] lllooooonggg dreeeeeeeaaaaammmm yeeeeeeah
2012-02-20 15:58:10.513 DreamerIOS[3037:10403] (null)
2012-02-20 15:58:10.516 DreamerIOS[3037:10403] dream to end
2012-02-20 15:58:10.516 DreamerIOS[3037:10403] (null)
2012-02-20 15:58:10.519 DreamerIOS[3037:10403] adsfhadskgh dfagfadkuy gadyv dsfdfad fsdf a ghfncdhg hjfg f dfj ghf 
2012-02-20 15:58:10.519 DreamerIOS[3037:10403] (null)

So, NSLog(@”%@”,tempDream.title); is OK, but NSLog(@”%@”,textLabel.text); is null. Why?

  • 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-30T04:03:21+00:00Added an answer on May 30, 2026 at 4:03 am

    It is because each time you add a new label to the cell.

    When you init a new cell, you add the label and set a tag to it

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    
        //  add label here
        ...
        [label setTag:999];
    }
    

    Then when you configure the cell, use [UIView viewWithTag:] to get the reference of the label

    UILabel *label = (UILabel *)[cell.contentView viewWithTag:999];
    

    update:

    You should use a constant value for the tag. If you use the indexPath as the tag, the view may not found. Since you are reusing the cell, the system only create a certain number of cells. When the cell is out of view (not visible), dequeueReusableCellWithIdentifier will get the cell for you rather than create a new cell.

    The reusableCell is a view that you create before.
    The case you use a dynamic value for the tag will like this:
    You are at cell 10(indexPath), the system find a reusableCell which is created at 3(indexPath). Since it was created at 3, the label tag is 3. But you find a view with tag 10, therefore the result is null.

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

Sidebar

Related Questions

I have got the following code: - (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath { TestViewController*detail = [self.storyboard instantiateViewControllerWithIdentifier:@TestView]; [self.navigationController pushViewController:detail animated: YES];
I'm building an app that contains an UITableview. I got tableview to work perfectly
I'm writing my first iphone app and through several examples I've got a UITableView
I ran the instruments for my app (which contains a UITableView) and got the
i'm sure there is a simple way to solve this problem, but I can't
So, I've got an UITableView showing the contents of the app Documents folder. In
I got this app where the user must connect the DB manually, I do
I've released my app and noticed the jerkyness when scrolling in the CellForRowAtIndexPath, this
I got an app running on my SQL Server that is starting to slow

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.