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);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…