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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:52:56+00:00 2026-06-11T17:52:56+00:00

I have an app where I load a large plist file in a tableview.

  • 0

I have an app where I load a large plist file in a tableview. This plist file is as a book. It contains chapters and lines. Each row has different length depending on the line length and therefore I need to resize the cell automatically.

I am using storyboard and standard tableview and cell. Cell style=basic and the cell label is set to text=plain lines=0 linebreaks=wordwrap

Up to there, no problem resizing the cell height to the proper size. As the cell height is defined before the text is inserted in the label we have to do it by the well known method of using CGsize and I do it like that (it’s working fine)

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:
      (NSIndexPath*)indexPath
{
    NSUInteger section = [indexPath section];
    NSString *key = [chapters objectAtIndex:section];
    NSArray *linesSection = [lines objectForKey:key];
    NSString* theText =  [linesSection objectAtIndex:indexPath.row];

    int labelWidth = LW_CHAPTERINDEX_10;
    if (chapters.count < 100){
        if (chapters.count < NB_MIN_CHAP){
            labelWidth = LABELWIDTH;
        } else {
            labelWidth = LW_CHAPTERINDEX_10;
        }
    }

    CGSize textSize = [theText sizeWithFont:[UIFont systemFontOfSize:14]
        constrainedToSize:CGSizeMake(labelWidth, MAXFLOAT) 
        lineBreakMode:UILineBreakModeWordWrap];

    return textSize.height;
}

The problem is the hardcoding depending on the index. For now I have 3 possibilites.

  • No index
  • Index with numbers below 10
  • Index with numbers below 100

and in the code this part

int labelWidth = LW_CHAPTERINDEX_10;
if (chapters.count < 100){
    if (chapters.count < NB_MIN_CHAP){
        labelWidth = LABELWIDTH;
    } else {
        labelWidth = LW_CHAPTERINDEX_10;
    }
}

is the hardcoding depending on the 3 possibilities.

I find this was of doing weird, especially if apple will start to deliver more different screen sizes.

QUESTION

How can I get the index width at runtime to determine my label width ?

For example i would like to program something like screen.width – index-width to get the label width.

Or any other that should allow it to be dynamical and no more statically hardcoded.

  • 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-11T17:52:58+00:00Added an answer on June 11, 2026 at 5:52 pm

    Unfortunately there is no (standard) way you can directly access the section index subview. However, you can use the methods for calculating the CGSize of text to determine dynamically the width of the section index.

    You could determine all possible strings to be returned by sectionIndexTitlesForTableView: beforehand and calculate the necessary size, perhaps padding with some extra pixels left and right. Maybe it is necessary to make some experiments to determine the correct font and size.

    Now your approach with something like screenSize.width - textSize.width - 2*PADDING should be viable. The only hardcoded thing is now the padding, which should not break things when new screen sizes are introduced.

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

Sidebar

Related Questions

I have an android app that has to load very large files on start
I have an app that has 2 tabs. Each tab loads an xml file
I have a Silverlight app that has to load an image dynamically, depending on
I have a GUI app written in C++/CLI which has a load of configurable
I have a web app that contains a slide show with about 10 large
I just got this quite large CakePHP app (about 20k lines of code), which
I have a very large CSV file and I need to write an app
I have a large array with around 20k objects in it. Each object has
I have this terribly large controller in my app. I'd really like to make
I have an Scrollview in my app that has quite a large amount of

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.