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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:56:30+00:00 2026-05-27T10:56:30+00:00

Just getting my feet wet with iOS development, so I hope I’m getting the

  • 0

Just getting my feet wet with iOS development, so I hope I’m getting the right level of detail here…

I have a UILabel, loaded in a Table cell created via a .xib. Actually several labels, one of which is of varying length (and therefore varying wrapped height). heightForRowAtIndexPath, etc. are properly overridden, and the required height for both labels is being calculated correctly and assigned to each’s .frame

Once both sizes have been set, I set the frame.origin.y of the smaller (fixed length, always one row high) label to match that of the larger label. This works as far as can be seen stepping through cellForRowAtIndexPath but on initial display of the newly-created cell, the origin seems to be not-quite-vertically-centered in the container, as opposed to stuck up top.

After clicking “through” the cell to a different view, and returning to the (now-reused, and presumably already properly-sized container), the position is set as before, and it appears where I expected it to.

It seems like the container is being resized after cellForRowAtIndexPath returns, and that somewhere in there a new position is found for our label; this would explain why reusing the cell later fixes the problem.

I’ve tried every apparently-sane combination of inner and outer Mode and Baseline settings, stretch settings, etc. At a loss for explanations and/or workarounds.

Update:

A suggestion on the Changing the position of custom UIButton in custom UITableViewCell question solved the problem. The solution was to subclass UITableViewCell and override layoutSubviews, thereby getting a chance to re-position the sub-elements after the TableView had done its normal positioning. Will close this once either that person responds here, or the bounty expires and I’ll answer myself, with code.

  • 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-27T10:56:31+00:00Added an answer on May 27, 2026 at 10:56 am

    If I do any complex layout in a UITableViewCell I try to keep it out of cellForRowAtIndexPath. One option is to do layout in - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath but I prefer to encapsulate layout in a custom UITableViewCell class.

    Make your own UITableViewCell subclass. Create and add the custom button / label / view to the cell’s contentView in your init method, or create and add it lazily via an accessor property. Override layoutSubviews and postion the button as desired.

    Something like this:

    @implementation MyCustomCell
    
    - (void) init
    {
        self = [super initWithStyle: UITableViewCellStyleDefault reuseIdentifier: nil];
        if ( self != nil )  
        {
             _myButton = [[UIButton buttonWithType: UIButtonTypeRoundedRect] retain];
             [self.contentView addSubview: _myButton];
        }
    
        return self;
    }
    
    - (void) layoutSubviews
    {
        [super layoutSubviews];
    
        // dynamic layout logic:
        if ( ... )
        {
    
             _myButton.frame = CGRectMake( 10, 10, 100, 30 );
        }
        else 
       {
             _myButton.frame = CGRectMake( 20, 10, 50, 30 );
    
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just getting my feet wet with Android and have built a UI that
just getting my feet wet with sql server express. I have what would be
Just getting my feet wet with some Fluent NHibernate AutoMap conventions, and ran into
I'm just getting my feet wet with Ember.js, and I've hit something that I'm
Just getting into SQL stored queries right now... anyway, here's my database schema (simplified
I'm just getting my feet wet with Linq and IEnumerable, and I'm needing help
I'm just getting my feet wet in Silverlight, and don't really understand the differences
Disclaimer: I'm new to unit testing and just getting my feet wet. That being
I am just getting my feet wet with stored procedures. According to the tutorials
I am an Android developer just getting my feet wet with BlackBerry. I am

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.