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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:37:14+00:00 2026-06-03T13:37:14+00:00

I’ve dragged a table view into my storyboard scene, but its height is static

  • 0

I’ve dragged a table view into my storyboard scene, but its height is static and won’t adjust based on how many cells it contains unless I manually adjust it in storyboard. How can I get this table to adjust its own height based on the total height of its contents?

  • 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-03T13:37:15+00:00Added an answer on June 3, 2026 at 1:37 pm

    You’re going to have to do some version of this:

    1. Figure out how many cells will be displayed
    2. Figure out the height for each cell
    3. Do the math and set the height of the UITableView

    Before you get mad (since I know that’s pretty obvious), let me follow up with this:

    1. If you know for sure how many cells will be displayed all the time (and it’s a static value), you can just manually adjust the height in Interface Builder.
    2. If you don’t know for sure (which I’m guessing is the case, based on your question), you’ll have to do #’s 1 thru 3 above at runtime. Then, because UITableView is a subclass of UIView, you can simply adjust its frame property.

    For example:

    1. I’ve got 7 cells.
    2. Cells 1, 3 and 5 (indices 0, 2 and 4) are 20 pixels tall.
    3. Cells 2, 4, 6 and 7 (indices 1, 3, 5 and 6) are 30 pixels tall.
    4. I need a total display height of 180 pixels (you might actually need to play with this because of separators, etc..)
    5. So, I can just call:

    CGFloat newHeight = ... // Whatever you calculate
    CGRect currentFrame = [[self MyTableView] frame];  
    [[self MyTableView] setFrame:CGRectMake(
                     currentFrame.origin.x,
                     currentFrame.origin.y,
                     currentFrame.size.width,
                     newHeight)
     ];
    

    If you want to get really fancy, you can animate the change by wrapping it in a [UIView animationWithDuration:] block.

    Hope this helps!


    Update/Edit

    Here’s a kludgy way to do it… it works, but I’m sure there’s a better way to do it. I do not claim this to be the best/fastest/most efficient way. This is more to show a principle. 😉

    - (CGFloat)totalHeightNeededForTableView:(UITableView *)tv {
        CGFloat retVal = 0;
    
        int sectionCount = [self numberOfSectionsInTableView:tv];
        int rowCount = 0;
        NSIndexPath *path = nil;
        for (int i = 0; i < sectionCount; i = i + 1) {
            rowCount = [self tableView:tv numberOfRowsInSection:i];
            for (int j = 0; j < rowCount; j = j + 1) {
                path = [NSIndexPath indexPathForRow:j inSection:i];
                retVal = retVal + [self tableView:tv heightForRowAtIndexPath:path];
            }
        }
        return retVal;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I need to clean up various Word 'smart' characters in user input, including but
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.