[英]setNeedsDisplay doesn't change UITableView's center
Added a UITableView
through IB . 通过IB添加了UITableView
。 I'm trying to change the center of the UITableView
programmatically: 我试图以编程方式更改UITableView
的中心:
- (IBAction)OnClickPrescribingDoctorButton:(id)sender
{
[_prescribingDoctorTableView setNeedsDisplay];
NSLog(@"check before %f",_prescribingDoctorTableView.center.y);
_prescribingDoctorTableView.center = CGPointMake(50,200);
NSLog(@"check after %f",_prescribingDoctorTableView.center.y);
}
LOG: 日志:
2014-04-21 13:40:18.898 SmartWatch[1833:70b] check before 788.000000
2014-04-21 13:40:18.898 SmartWatch[1833:70b] check after 200.000000
2014-04-21 13:40:20.075 SmartWatch[1833:70b] check before 788.000000
2014-04-21 13:40:20.075 SmartWatch[1833:70b] check after 200.000000
As you can see in the log, the Y-axis value of the UITableView
changes but i don't see any effect visually or the UITableView
being redrawn as i call setNeedsDisplay and i also don't understand why does Y-axis value value reverts back to 788 every time i call this code by clicking on a UIButton
. 正如您在日志中看到的那样, UITableView
的Y轴值发生了变化,但是在我调用setNeedsDisplay时 ,我看不到任何视觉效果或UITableView
正在重绘,而且我也不明白为什么Y轴值会还原每次我通过单击UIButton
调用此代码时,返回788。
Try using [[_prescribingDoctorTableView superview] setNeedsLayout] instead of [_prescribingDoctorTableView setNeedsDisplay] to layout the subviews. 尝试使用[[_prescribingDoctorTableView superview] setNeedsLayout]而不是[_prescribingDoctorTableView setNeedsDisplay]来布局子视图。
if this doesn't work, subclass your view and override the methods, 如果这不起作用,请子类化您的视图并覆盖方法,
- (void)layoutSubviews (or) - (void)setFrame:(CGRect)frame
And debug by placing the break point in these methods so that you can come to know from where your frame being updated. 并通过在这些方法中放置断点进行调试,以便您可以从中更新框架。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.