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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:53:22+00:00 2026-06-15T05:53:22+00:00

I have a list view that sometimes has long text. When the text is

  • 0

I have a list view that sometimes has long text. When the text is a few paragraphs, it tends to get cut off at some point. Part of the strange behavior is that it does not always get cut off at the same character, but kind of random.

Here is the code that I use to populate the list:

// CREATING EACH CELL IN THE LIST
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{    
    //static const NSInteger kLabelTag = 1;
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault)
            reuseIdentifier:@"business"];

    NSString *comment = [[items_array objectAtIndex:[indexPath row]] objectForKey:(@"comment")];
    NSString *first_name = [[items_array objectAtIndex:[indexPath row]] objectForKey:(@"first_name")];
    //Boolean *is_private = [[items_array objectAtIndex:[indexPath row]] objectForKey:(@"is_private")];

    // Creating a constraint size for the label you are making
    CGSize constraint = CGSizeMake(320 - (10 * 2), 20000.0f); 

    // Determining the size that you will need for the label based on the comment
    // length and the contraint size
    CGSize size = [comment sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap]; 

    //  Creating the label and initializing it with the frame that you have
    //  determined by your size calculations above
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, MAX(size.height, 44.0f) + 20.0f)];

    // setting up the label properties
    label.numberOfLines = 0;
    label.lineBreakMode = UILineBreakModeWordWrap;

    standardUserDefaults = [NSUserDefaults standardUserDefaults];
    NSString *is_private = [standardUserDefaults objectForKey:@"is_private"];

    if ( is_private == nil )
    {
        label.text = [first_name stringByAppendingString:[@": "  stringByAppendingString:comment]]; // comment;
    }
    else
    if ( [is_private isEqualToString:@"0"])
    {
        label.text = [first_name stringByAppendingString:[@": "  stringByAppendingString:comment]]; // comment;     
    }
    else 
    {
        label.text = comment;  
    }

    // adding the label view to the cell that you have created
    [cell.contentView addSubview:label];        

    // CLOSE THE SPINNER
    [spinner stopAnimating];

    // return the cell for the table view
    return cell;
}

//This method will determine how tall each row needs to be. Cell size for word wrapping.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{    
    NSString *comment = [[items_array objectAtIndex:[indexPath row]] objectForKey:(@"comment")];

    // Again you are getting the constraints because you are going to us this size
    // to constrain the height of the cell just like you determined the size for the label.
    CGSize constraint = CGSizeMake(320 - (10 * 2), 20000.0f);

    // Again, determining the size that we will need for the label, because it will drive
    // the height of the cell
    CGSize size = [comment sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap]; 

    //  Finally, we can determine the height for the cell!
    CGFloat height = MAX(size.height, 44.0f);

    //  return the height, which is the height of the label plus some extra space to make
    //  it look good.
    return height + (10 * 2);
}

Does this code have anything particularly incorrect with it? Or is the problem possibly rooted elsewhere?

Thanks!

  • 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-15T05:53:33+00:00Added an answer on June 15, 2026 at 5:53 am

    when you create the label, you hand it a max height

    MAX(size.height, 44.0f)
    

    which means the label is never higher than 44 points.
    If the text (which is being wrapped to fit the width of the label) is higher than the label, the lines that fallow below it will still be in the label, but not visible.

    Your options :

    -Make the label font auto sizing

    -change the height, or switch to dynamic height for the label

    this would go something like this every time you update it:

    myLabel.text = @"some text";
    CGRect rect = myLabel.frame;
    rect.size.height = textView.contentSize.height;// Adding.size Since height is not a member of CGRect
    textView.frame = rect; //your label is now as high as its contents (the text)
    

    -trim the text that goes into the label so it never exceeds the height of the label.

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

Sidebar

Related Questions

I have a list view that displays a collection of items, each item has
I have noticied that in some android menues, a list view is shown that
I have a picker view that has a list of numbers to pick from.
I have this MVC view that has a list of images, these images are
I have used a list view that uses a grid view in WPF. I
I have created a list view that displays the names and dates of items
I have a custom list view that is getting data from server and changing
I have a list view with many rows and have it set so that
I have a standard list view setup with backbone that looks something like below.
I have a view that renders a list elements using the following template :

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.