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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:46:40+00:00 2026-05-16T20:46:40+00:00

The proper height for my custom UITableViewCells depends on their width. Unfortunately, it is

  • 0

The proper height for my custom UITableViewCells depends on their width. Unfortunately, it is difficult to know the actual content area width of a cell in -tableView:heightForRowAtIndexPath:, since the only information I have to work with is the tableview. Several factors can change the content width so it is not equal to tableView.bounds.size.width; the one I’m struggling with now is the section index. (Another is if the tableview is grouped.)

Is there a good way in general to get the cell content width from just the tableView?

Failing that, is there any way to get the width of the section index, so that I can subtract it from the bounds width? (I don’t want to hard code it, since that won’t be portable across devices.)

Note: This is not a dup of Need access to the cell in the tableView:heightForRowAtIndexPath: because the solution there is just to use the bounds. Nor is it a dup of Get tableView:heightForRowAtIndexPath: to happen after tableView:cellForRowAtIndexPath:? since the solution there is to hard code a constant (265.0), which isn’t portable across devices.

  • 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-16T20:46:40+00:00Added an answer on May 16, 2026 at 8:46 pm

    Here’s what I got working. It’s ugly, but it works, at least in all the cases I could find.

    - (CGFloat)sectionIndexWidthForSectionIndexTitles:(NSArray *)titles {
      UIFont *sectionIndexFont = [UIFont fontWithName:@"Helvetica-Bold" size:14.0f];
      CGFloat maxWidth = CGFLOAT_MIN;
      for(NSString *title in titles) {
        CGFloat titleWidth = [title sizeWithFont:sectionIndexFont].width;
        maxWidth = MAX(maxWidth, titleWidth);
      }
    
      CGFloat sectionIndexWidth = 0.0f;
      NSUInteger maxWidthInt = (int)maxWidth;
      switch(maxWidthInt) {
        case 0:
          sectionIndexWidth = 0.0f;
          break;
        case 11:
          sectionIndexWidth = 30.0f;
          break;
        case 12:
          sectionIndexWidth = 31.0f;
          break;
        case 14:
          sectionIndexWidth = 32.0f;
          break;
        default:
          sectionIndexWidth = 0.0f;
          break;
      }
    
      return sectionIndexWidth;  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume I have a bean DialogBox, with properties for height and width: public class
If I have something like this: <p>Element<p> <iframe src = otherPage.html style = width:100%;height:100%>
I have an Accordion and the height of its content can be dynamically resized.
This how i construct my PLIST. <dict> <key>level1</key> <dict> <key>formation</key> <dict> <key>height</key> <integer>34</integer> <key>width</key>
Is there a proper way to display text at the descent height of a
Instead of specifying the width and height of a Raphael canvas, I need it
I'm trying to create a custom layout that it automatically sets it's dimensions, height
I've checked some answers for the overlay full height problem, but there's no proper
What is the proper way to implement Custom Properties in Silverlight UserControls? Every "Page"
I remember reading a style guide explaining what the proper line-height should be for

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.