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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:21:25+00:00 2026-05-25T03:21:25+00:00

I’m currently trying to get a UITableView to use custom cell heights based on

  • 0

I’m currently trying to get a UITableView to use custom cell heights based on text in an array. The problem I’m seeing is that the text seems to squish together at point rather than filling the full length of a custom cell. This results in the text overlapping over cells, sometimes disappearing under them.

Here’s the code I have for determining the cell height, I’m not sure of the standard UILabel text height but this seemed to work well at the height I for the font.

if (indexPath.section == 0) {

    NSString *text = [[self.recipeDict objectForKey:@"Ingredients"] objectAtIndex:[indexPath row]];

    CGSize constraint = CGSizeMake(320 - (10 * 2), 20000.0f);

    CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];

    CGFloat height = size.height;

    return height + 20;
}

Also just in case the creation of the cells is either a hinderance to my problem or just helps you know what’s going on, here’s that too.

UITableViewCell *cell;
UITableViewCell *ingredientCell;
UITableViewCell *methodCell;

if (indexPath.section == 0) {
    UILabel *ingredientText;

    static NSString *ingredientCellIdentifier = @"Ingredient Cell";

    ingredientCell = [tableView dequeueReusableCellWithIdentifier: ingredientCellIdentifier];

    if (ingredientCell == nil)
    {
        ingredientCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: ingredientCellIdentifier] autorelease];

        ingredientText = [[UILabel alloc] initWithFrame:CGRectMake(15, 7, 290, 44)];
        [ingredientText setLineBreakMode:UILineBreakModeWordWrap];
        [ingredientText setNumberOfLines:0];
        [ingredientCell.contentView addSubview:ingredientText];

        ingredientText.tag = 1;

        [ingredientText release];

        ingredientCell.contentMode = UIViewContentModeRedraw;
    }

    ingredientText = (UILabel*)[ingredientCell viewWithTag:1];
    ingredientText.text = [[self.recipeDict objectForKey:@"Ingredients"] objectAtIndex: indexPath.row];
    [ingredientText sizeToFit];

    return ingredientCell;
}

This is my second attempt at solving this issue but it seems to be beyond my current ability so I welcome wisdom gained through experience.

UPDATE –

After further investigation it seems that the UILabel ingredientText being resized is causing the issue.

It starts out as tall as it needs to be for the text shown, however when that label is redrawn with a larger height for another piece of text which requires more lines it’s never shrunk down again. It seems that the sizeToFit method is prioritising using the available height rather than taking up the width and shrinking the height.

Right now I’ve set the width again after the sizeToFit which works around the issue but it leads to odd spacing depending on the height of the label.

  • 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-25T03:21:26+00:00Added an answer on May 25, 2026 at 3:21 am

    The solution to this issue was that the width specified in the constant in the cell height method didn’t match the frame for the cell text specified later in the cellForRowAtIndexPath method.

    Once these are the same the problem resolves itself.

    The different constant size led to inconsistent and inaccurate UILabel heights being reported. This led to incorrect table row heights being set.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I am currently running into a problem where an element is coming back from
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

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.