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

  • SEARCH
  • Home
  • 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 9033799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:19:20+00:00 2026-06-16T08:19:20+00:00

This has just completely stomped me. I have a custom UIView and UILable that

  • 0

This has just completely stomped me.

I have a custom UIView and UILable that I have added to my UITableView in cell.contentView as a subview. I have an array called arryData with about 100 strings as data in it that I want to show in my table. The problem is that when table is created I see the first 0-4 rows from my arryData with values and if I keep scrolling down the table, all I see are the first 5 strings repeating over and over. What am I doing wrong? here is my code.

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    //NSLog(@"Inside cellForRowAtIndexPath");

    static NSString *CellIdentifier = @"Cell";

    // Try to retrieve from the table view a now-unused cell with the given identifier.
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    UILabel *labelValue1 = [[UILabel alloc] initWithFrame:CGRectMake(70, 25, 200, 30)];

    // If no cell is available, create a new one using the given identifier.
    if (cell == nil)
    {
        // Use the default cell style.
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        //cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

        UIImageView *imgVw1 = [[UIImageView alloc] initWithFrame:CGRectMake(11, 0, 300, 75)];
        imgVw1.image = [UIImage imageNamed:@"background_pic5.png"];
        imgVw1.userInteractionEnabled = YES;
        imgVw1.exclusiveTouch = YES;
        [cell.contentView addSubview:imgVw1];


        labelValue1.text = [arryData objectAtIndex:indexPath.row];
        labelValue1.font = [UIFont fontWithName:@"BradleyHandITCTT-Bold" size: 22.0];
        labelValue1.textColor = [UIColor whiteColor];
        labelValue1.textAlignment = UITextAlignmentCenter;
        labelValue1.numberOfLines = 1;
        labelValue1.backgroundColor = [UIColor clearColor];
        labelValue1.adjustsFontSizeToFitWidth = YES;
        labelValue1.minimumFontSize = 10.0;
        labelValue1.tag = (indexPath.row)+100;
        [cell.contentView addSubview:labelValue1];

        NSLog(@"indexPath.row: %d - arrayData: %@..." , indexPath.row, [arryData objectAtIndex:indexPath.row]);
    }
    else
    {
        NSLog(@"indexPath.row: %d - arrayData: %@..." , indexPath.row, [arryData objectAtIndex:indexPath.row]);

        labelValue1 = (UILabel *) [cell viewWithTag:((indexPath.row)+100)];
        labelValue1.text = [arryData objectAtIndex:indexPath.row];
    }

    //Do this only if row has a value. For blank ones, Skip this


    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) 
    {
        //its iphone
        cell.textLabel.font = [UIFont systemFontOfSize:13];
    }


    if([arryDataMutable containsObject:indexPath])
    {
        [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
    } 
    else 
    {
        [cell setAccessoryType:UITableViewCellAccessoryNone];
    }

    //cell.backgroundColor = [UIColor whiteColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;

}

This is what my output looks like when I scroll down the table and all I keep seeing is text in my labelValue1 from indexPath.row 0 – 4 repeat over and over

indexPath.row: 0 - arrayData: Behind Whipped...
indexPath.row: 1 - arrayData: Aftershock Whip...
indexPath.row: 2 - arrayData: Bull Whipped Sound 1...
indexPath.row: 3 - arrayData: Bull Whipped Sound 2...
indexPath.row: 4 - arrayData: Bullet Fire Whip...
indexPath.row: 5 - arrayData: Circus Whip...
indexPath.row: 6 - arrayData: Circus Whip2...
  • 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-06-16T08:19:21+00:00Added an answer on June 16, 2026 at 8:19 am

    Change the way you are setting tag in this case,

    labelValue1.tag = 100;
    

    and read it as,

    labelValue1 = (UILabel *) [cell viewWithTag:100];
    

    Since you are dequeuing the cells, it will try to reuse the cell and label is added to that when you are allocating memory for the cell. When the else part is executed, you need to access the same label which was already added as [cell viewWithTag:100];.

    [cell viewWithTag:((indexPath.row)+100)]; will return nil for most of the cells which were not visible for the first time. Since you are reusing cells, you will see the same first 5 visible cells again with same text. In this case, you were trying to set text to a nil object. So it wont make any difference and hence you will see the same text repeating.

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

Sidebar

Related Questions

When I have this, the div, which just has text in it, uses all
I translated this code(it has bad side effect that it just capture the outer
I have an issue that has just recently come to my attention. We have
Ok, so this has me completely stumped just like the guy here with the
I have an odd problem that has me completely stumped. Unfortunately I have a
i just wanted to put a selection on my picturebox.image but this has just
This has already been asked here , but I am just not satisfied with
I know this has been asked thousands of times but I just can't find
I know this has been asked different ways several times, but I'm just not
I know this has been asked before, but I just cant seem to find

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.