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);
contentView
? This week i got project to work with, and there used-heightForRowAtIndexPath
tableview datasource(?) method to set width of controls in tableView's cells. – Edouard-heightForRowAtIndexPath
. That's not good approach mb but i think it will work. – Edouardfloat x=frameAfterResize.origin.x+frameAfterResize.size.width;
you can simply writefloat x=CGRectGetMaxX(frameAfterResize);
– Arnaldo