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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:05:27+00:00 2026-05-20T14:05:27+00:00

I add two UILabels to a UITableViewCell and then name and number labels to

  • 0

I add two UILabels to a UITableViewCell and then name and number labels to that cell. When I reload the data in the UITableView (whether I add or delete a contact from the table view) the data in the labels are overlapping which means it’s not reloading the labels, until the entire view is reloaded.

Can anyone please help?

Code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    UILabel *name;
    UILabel *number;

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

        //NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
        //      NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
        //      [sortDescriptor release];
    }
    CGRect Label1Frame = CGRectMake(10, 10, 140, 25);
    name = [[UILabel alloc] initWithFrame:Label1Frame];
    name.tag = 1;
    [name setBackgroundColor:[UIColor clearColor]];
    [cell.contentView addSubview:name];

    CGRect Label2Frame = CGRectMake(150, 10, 140, 25);
    number = [[UILabel alloc] initWithFrame:Label2Frame];
    number.tag = 1;
    [number setBackgroundColor:[UIColor clearColor]];
    [cell.contentView addSubview:number];

    name.text = [NSString stringWithFormat:@"%@",[names objectAtIndex:indexPath.row]];
    number.text = [NSString stringWithFormat:@"%@",[phonenumbers objectAtIndex:indexPath.row]];

    [name release];
    [number release];
    return cell;    
}
  • 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-20T14:05:28+00:00Added an answer on May 20, 2026 at 2:05 pm

    You should move your label creation code inside the cell initialization and then just reference them later by tag like this:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        static NSString *CellIdentifier = @"Cell";        
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    
            //NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
            //      NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
            //      [sortDescriptor release];
            CGRect Label1Frame = CGRectMake(10, 10, 140, 25);
            UILabel *name = [[UILabel alloc] initWithFrame:Label1Frame];
            name.tag = 1;
            [name setBackgroundColor:[UIColor clearColor]];
            [cell.contentView addSubview:name];
            [name release];
    
            CGRect Label2Frame = CGRectMake(150, 10, 140, 25);
            UILabel *number = [[UILabel alloc] initWithFrame:Label2Frame];
            number.tag = 2;
            [number setBackgroundColor:[UIColor clearColor]];
            [cell.contentView addSubview:number];
            [number release];
        }
    
        UILabel *nameLabel = (UILabel *)[cell viewWithTag:1];
        UILabel *numberLabel = (UILabel *)[cell viewWithTag:2];
        name.text = [NSString stringWithFormat:@"%@",[names objectAtIndex:indexPath.row]];
        number.text = [NSString stringWithFormat:@"%@",[phonenumbers objectAtIndex:indexPath.row]];
    
        return cell;    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add two extra rows to my UITableView. Data comes from the
Need to add two same name .csproj class libraries in my solution.Have two project
I'm trying to add two object that they are in the same class. In
I want to add two lists of a numeric type such that addedList[x] =
try the following: add two divs to a page with the same class name.
How add two images side by side in a UITableViewCell? The style of UITableViewCell
I'm having trouble adding button to my UITableViewCell , the cell has two UILabel
I'm trying to add two buttons to each cell in a tableview, but when
When I add two connection strings in the web.config, an error appears that tells
In this following code I intend to programmatically add two labels in each row

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.