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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:42:05+00:00 2026-05-20T15:42:05+00:00

heightForRowAtIndexPath is never displaying multiline when the text is longer than usual. Here is

  • 0

heightForRowAtIndexPath is never displaying multiline when the text is longer than usual.

Here is my code:

#define FONT_SIZE 14.0f
#define CELL_CONTENT_WIDTH 320.0f
#define CELL_CONTENT_MARGIN 10.0f

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat     result = 44.0f;
    CGFloat     width = 0;
    CGFloat     tableViewWidth;
    CGRect      bounds = [UIScreen mainScreen].bounds;

    if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
        tableViewWidth = bounds.size.width;
    else
        tableViewWidth = bounds.size.height;

    width = tableViewWidth - 110;       // fudge factor, 115 isn't quite right

    NSUInteger index = [indexPath row];
    id doc = [[self displayedObjects] objectAtIndex:index];

    NSString *title = [doc title];  

    if (title)
    {
        // The notes can be of any height
        // This needs to work for both portrait and landscape orientations.
        // Calls to the table view to get the current cell and the rect for the 
        // current row are recursive and call back this method.
        CGSize      textSize = { width, 20000.0f };     // width and height of text area
        CGSize      size = [title sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:textSize lineBreakMode:UILineBreakModeWordWrap];

        size.height += 29.0f;               // top and bottom margin
        result = MAX(size.height, 44.0f);   // at least one row
    }

    return result;
}

Any help will be really appreciated.
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-05-20T15:42:05+00:00Added an answer on May 20, 2026 at 3:42 pm

    To make label show multiline text you must set its numberOfLines property to a maximum allowed number of lines (or to 0 for arbitrary lines number). So in cellForRowAtIndexPath: method when setup your cell add:

    ...
    cell.textLabel.numberOfLines = 0;
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: - (CGFloat)tableView:(UITableView *) tableView heightForRowAtIndexPath:(NSIndexPath *) indexPath{ TestCell* cell
I'm using the following code to size a UITableViewCellStyleSubtitle cell to fit text that
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if([tableView.somethingMagicalHereThatAllowsMeKnowWhichCellItIs isEqualToString:@CellType]){ return 50; } return 25;} I
In -tableView:heightForRowAtIndexPath: I'm changing the height for a cell dynamically during usage of the
In my heightForRowAtIndexPath method I want to customize height only for certain rows. For
I am overloading the delegate method -tableView:heightForRowAtIndexPath: and using -sizeWithFont:constrainedToSize: to programmatically set the
Do I need to set heightForRowAtIndexPath if I am using a custom UITableViewCell? In
I need to access my cell in the table from tableView:heightForRowAtIndexPath: since I want
I am setting my height: - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { CGFloat rowHeight =
Instruments tells me there's a mem leak in this code, but I can't seem

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.