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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:33:37+00:00 2026-05-24T09:33:37+00:00

My goal is to display 2 strings in the same cell, one of them

  • 0

My goal is to display 2 strings in the same cell, one of them left aligned and the other right aligned. The code I have attached does just that in a table view, however it breaks when you scroll up/down. I need this to work in a table that can scroll. Someone had mentioned using CustomUITableViewCells instead of my current method, can anyone point me to an example of this?

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

        static NSString *CellIdentifier = @"Cell";

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

            UILabel *rank = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 100, 20];
            [rank setTag:5];
            [cell.contentView addSubview:rank];
            [rank release];

            UILabel *item = [[UILabel alloc] initWithFrame:CGRectMake(110, 5, 220, 20];
            [item setTextAlignment:UITextAlignmentRight];
            [item setTag:6];
            [cell.contentView addSubview:item];
            [item release];
        }

        UILabel *rank = (UILabel *)[cell viewWithTag:5];
        UILabel *item = (UILabel *)[cell viewWithTag:6];

        rank.text = @"leftside";
        item.text = @"rightside";
    }

Any ideas and thoughts greatly appricated, thanks for lookin
  • 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-24T09:33:37+00:00Added an answer on May 24, 2026 at 9:33 am

    This problem is because of dequeueReusableCellWithIdentifier. While the cell is being re-used, and when you scroll up and down it will cause major problems as labels are being added as subviews to the cells and they do not have the properties of the cell. However, if you use the cell.textLabel as your label, it would not cause problems like the one you are facing now, but you cannot add more than one label.

    You have two solutions for this.

    1. In your case, you need to stop using the same cellIdentifier for each and use different identifiers for each cells so that they do not get reused. This would be helpful if you have a very small number of rows in the tableView or it would turn out to be inefficient.

    2. A better solution would be to subclass UITableViewCell and add those two labels in it’s code, and then use that UITableViewCell with dequeueReusableCellWithIdentifier. This is just a small amount of work, and you get to re-use cells. This would be very helpful if you have a large number of rows in your tableview.

      Go through THIS TUTORIAL to learn on how to subclass UITableViewCell with 2 labels.

      You will need to work with the method, - (void)layoutSubviews and add those labels to your custom UITableViewCell subclass.

    And remember to reference this customUITableViewCell instead of the default uitableviewcell when you are loading up the tableView. Your UILabels will not be messed up anymore.

    Another reference.

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

Sidebar

Related Questions

In my forum I have a BB code to display youtube videos. following options
My goal is to display two <div> s side-by-side with the content from both
On a Drupal app, my goal is to display a page with a couple
GOAL : To customize the background view of cell. Here is what I am
I have a ListBox to which I bound a sorted list of strings. I
I have the following code in child window which is working but what I
A common occurrence I have with one particular project is that it requires the
I am new to PL/SQL but have plenty of other SQL experience, including Oracle
The goal of my test program is to erase a cell in a simple
I have manage to display local health center listings from my database to a

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.