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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:50:05+00:00 2026-05-15T18:50:05+00:00

i am creating a UITableview cell in the following way const NSInteger TOP_LABEL_TAG =

  • 0

i am creating a UITableview cell in the following way

const NSInteger TOP_LABEL_TAG = 1001;

UILabel *topLabel;

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{

    cell =[[[UITableViewCell alloc] initWithFrame:CGRectZero             reuseIdentifier:CellIdentifier]
     autorelease];

    UIImage *indicatorImage = [UIImage imageNamed:@"indicator.png"];

     cell.accessoryView =[[[UIImageView alloc] initWithImage:indicatorImage]
     autorelease];

   const CGFloat LABEL_HEIGHT = 25;

    UIImage *image = [UIImage imageNamed:@"64x64.png"];

      topLabel =[[[UILabel alloc] initWithFrame:CGRectMake(
                 image.size.width + 2.0 * cell.indentationWidth,
                 0.8 * (tableView.rowHeight - 1.7 * LABEL_HEIGHT),
                 tableView.bounds.size.width -
                 image.size.width - 4.0 * cell.indentationWidth
                 - indicatorImage.size.width,
                 LABEL_HEIGHT)] autorelease];

    [cell.contentView addSubview:topLabel];


        topLabel.tag = TOP_LABEL_TAG;

    topLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
    topLabel.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.9 alpha:1.0];

    topLabel.font = [UIFont systemFontOfSize:20];
    topLabel.textAlignment== UITextAlignmentCenter;

}

else
{

    topLabel = (UILabel *)[cell viewWithTag:TOP_LABEL_TAG];
}   

topLabel.text =  [NSString stringWithFormat:[aboutArray objectAtIndex:[indexPath row]]];
topLabel.textAlignment=UITextAlignmentCenter;

first time when the table loads the tableView works fine.But when i navigate back to this page from another page the text in the first cell of table moves on the right and only half of it visisble..What could be the possible reason for it??

  • 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-15T18:50:05+00:00Added an answer on May 15, 2026 at 6:50 pm

    There are a few bugs here working together to give you troubles.

    For starters, I think you might be assuming that the dequeued reusable cell has all the same data in it that it had when you get it back. The way it actually works is you may get back the same cell, but you will probably get a different cell, which is left over from the top or bottom depending on the scroll direction. As cells go out of view, they are flagged as reusable in no predictable order. So, remove that else block, and move all the logic (other than the init + autorelease outside of the if block. This way, all you are really checking is if you need to allocate new memory.

    Secondly, you have == UITextAlignmentCenter, you probably want to use =

    Thirdly, the math you are using to calculate your label geometry is suspect. It seems you are loading an image, then using the size of that image and the table bounds to dynamically calculate a new label frame. I would seriously consider a new way of approaching this label frame calculation. Are you sure this is the only way you can do it? It seems to me your label frame math ought to be the same every time.

    I’ve cleaned it up a bit so it’s readable and put it below with comments to better illustrate what I’m trying to say. Hope this helps.

    // initialize cell if need be
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
      cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }
    
    // setup the accessory
    UIImage *indicatorImage = [UIImage imageNamed:@"indicator.png"];
    cell.accessoryView = [[[UIImageView alloc] initWithImage:indicatorImage] autorelease];
    
    
    // TODO: rewrite this 
    UIImage *image = [UIImage imageNamed:@"64x64.png"];
    const CGFloat LABEL_HEIGHT = 25;
    CGFloat x = image.size.width + 2.0 * cell.indentationWidth;
    CGFloat y = 0.8 * (tableView.rowHeight - 1.7 * LABEL_HEIGHT);
    CGFloat w = tableView.bounds.size.width - image.size.width - 4.0 * cell.indentationWidth - indicatorImage.size.width;
    CGFloat h = LABEL_HEIGHT;
    CGRect labelFrame = CGRectMake(x,y,w,h);
    
    // build a label and use it as the content view
    UILabel* topLabel = [[[UILabel alloc] initWithFrame:labelFrame] autorelease];
    topLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
    topLabel.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.9 alpha:1.0];
    topLabel.font = [UIFont systemFontOfSize:20];
    topLabel.textAlignment = UITextAlignmentCenter;
    topLabel.text = [NSString stringWithFormat:[aboutArray objectAtIndex:[indexPath row]]];
    topLabel.textAlignment = UITextAlignmentCenter;
    
    [cell.contentView addSubview:topLabel];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Creating a patch is very easy in SubVersion, With Tortoise, you right-click and select
Creating hashes of hashes in Ruby allows for convenient two (or more) dimensional lookups.
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
Creating an XPathDocument with referenced DTD sometimes throws a web exception. Why?
When creating a web application, and lets say you have a User object denoting
While creating a file synchronization program in C# I tried to make a method
When creating a criteria in NHibernate I can use Restriction.In() or Restriction.InG() What is
While creating classes in Java I often find myself creating instance-level collections that I
When creating a UserControl in WPF, I find it convenient to give it some
When creating a setup/MSI with Visual Studio is it possible to make a setup

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.