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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:20:48+00:00 2026-05-27T08:20:48+00:00

I need to change the position of UIButton dynamically. I do this in cellForRowAtIndexPath:

  • 0

I need to change the position of UIButton dynamically. I do this in cellForRowAtIndexPath:. I alter the frame of the button in that method. The change is not displayed when the table is initially displayed. But when I scroll past the cells and come back to it, it gets displayed. Similarly, when I first scroll to cells not visible initially, there is no change. The change occurs when I scroll to it the second time.

I have tried setNeedsDisplay: on both the custom button and the table view. I have done this even in willDisplayCell:forRowAtIndexPath:. How do I solve this?

EDIT: I forgot to mention that I am loading the UITableViewCell from a nib file. Here is the code to resize the frame.

label1.text  = //text from some source
label1.text = [label1.text stringByAppendingString:@"  |"];
[label1 sizeToFit];
CGRect frameAfterResize=label1.frame;
float x=frameAfterResize.origin.x+frameAfterResize.size.width;
button.frame=CGRectMake(x+2, button.frame.origin.y, button.frame.size.width,button.frame.size.height);
  • 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-27T08:20:49+00:00Added an answer on May 27, 2026 at 8:20 am

    Make your own UITableViewCell subclass. Create and add the button 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 );
    
       }
    }
    

    Alternatively, you can attempt to do cell layout in - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

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

Sidebar

Related Questions

all I need to change the position of a ImageView dynamically and iam using
I need change background of all text that have two spaces from the start
I need to change an element's ID using jQuery. Apparently these don't work: jQuery(this).prev(li).attr(id)=newid
I need to change the order of headers, I'm using this: HttpWebRequest request =
I have this css styling and was wondering what I need to change in
Evening all! I have half a script that I need to change the CSS
I need to change the position of an element i'm loading with ajax .
I need to get an dynamically added view position in LinearLayout with vertical orientation.
I need a class to change background-position on hover. What am I doing wrong?
I need to be able change the position of a background image in a

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.