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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:22:27+00:00 2026-06-07T20:22:27+00:00

I am trying to resize the height of a UITableViewCell depending on what text

  • 0

I am trying to resize the height of a UITableViewCell depending on what text is being displayed. I want the text to be fully shown.

I create a cell with specific TEXT_CELL label, in cellForRowAtIndexPath

if ([rowType isEqualToString:kTextCell] ) {

        cell = [[[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];

        // Create a text view;
        UITextView *newText = [[UITextView alloc] initWithFrame:CGRectZero];
        newText.backgroundColor = [UIColor blueColor];
        newText.tag = kNotesTag;
        newText.editable = NO;
        newText.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

        cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        [cell.contentView addSubview:newText];

        [newText release];
}

And when I display the cell, I figure out the size required to show all the text using sizeOfFont function. Then I set that size as a variable, which is used in the heightOfCell function.

    UITextView *notes = (UITextView*) [cell viewWithTag:kNotesTag];

    if (notes != nil) {
        notes.text = [self.managedObject dispalyValueForKeyPath:rowKey];

        // resize it to the right height          
        CGRect contentFrame = cell.contentView.frame;

        CGSize textSize = [notes.text sizeWithFont:[UIFont systemFontOfSize:[UIFont systemFontSize]] 
                                 constrainedToSize:CGSizeMake(contentFrame.size.width, CGFLOAT_MAX) 
                                     lineBreakMode:UILineBreakModeWordWrap];   

        CGFloat newHeight = textSize.height + (CELL_CONTENT_MARGIN*2); //some space at the bottom

        CGFloat textHeight = self.storedTextHeight;            

        if (textHeight != newHeight) {

            [notes setFrame:CGRectMake(contentFrame.origin.x, 
                                       CELL_CONTENT_MARGIN+contentFrame.origin.y, 
                                       contentFrame.size.width, newHeight)];

            self.storedTextHeight = newHeight;

            // we reset the height fo the row, so reload it
            [tView beginUpdates];
            [tView endUpdates];  

        }

The calculation works as expected, and the heightForRow is called, and the cell height is updated. However, I always get SIGABT at the [tView endUpdates] line.

The error message is below. I googled a bunch, but not clear why this is the case. Not creating or adding cells.

* Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).’

Thanks for any insight on this.

  • 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-07T20:22:28+00:00Added an answer on June 7, 2026 at 8:22 pm

    Your crash report indicates the problem might not be stemming from your resizing strategy. It says that the number of rows is changing, but you aren’t changing the number of rows yourself. This is happening because of the way you reload your table.

    To reload your table view, you should just call [tView reloadData] instead of -beginUpdates and -endUpdates.

    If you use -beginUpdates and -endUpdates, the table view will think you are making changes to the table manually, i.e. with -deleteRowsAtIndexPaths:withRowAnimation: and the lot. If you aren’t doing that (if you aren’t actually doing any updates yourself, which you aren’t), you should just be calling -reloadData. If you want to use -beginUpdates and -endUpdates, then between the two calls you can insert:

    [tView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:firstIndexPathToDelete, 
        someOtherIndexPathToDelete, maybeOneMoreIndexPathToDelete, nil] 
        withRowAnimation:UITableViewRowAnimationFade];
    

    between the call to -beginUpdates and -endUpdates.

    Edit:

    To help the performance of -reloadData, you need to make sure you aren’t doing a lot of heavy lifting in -cellForRowAtIndexPath:, and also that you are reusing cells. There are lots of articles on the internet about table view performance:

    How expensive is UITableView's reloadData?

    reloadData in tableView makes performance slow

    Discussion here

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

Sidebar

Related Questions

I'm trying to resize a UITextView that I have in a UITableViewCell. I want
I'm trying to get a row in my table view to resize its height,
So, I want to resize images to a FIXED width, but proportional height. I
I'm trying to create thumbnail and resize image at the same time, so to
I'm trying to dynamicly resize text within a div so that the text does
My problem is the next: I am trying resize a image size depending a
I'm trying to resize at run-time a textbox' height when the user presses the
I'm trying to resize an image in pygame. I want my background image to
I'm trying <iframe height=100% ...> but it still doesn't resize it. When i try
I want to create a UITableView with varying row heights, and I'm trying to

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.