1

UITableView通过IB添加了一个。我正在尝试以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);
}

日志:

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

正如您在日志中看到的那样,Y 轴值发生了UITableView变化,但我没有看到任何视觉效果或在我调用setNeedsDisplayUITableView时被重绘,我也不明白为什么Y 轴值会恢复为788 每次我通过单击调用此代码时。UIButton

4

1 回答 1

0

尝试使用 [[_prescribingDoctorTableView superview] setNeedsLayout] 而不是 [_prescribingDoctorTableView setNeedsDisplay] 来布局子视图。

如果这不起作用,请将您的视图子类化并覆盖方法,

- (void)layoutSubviews (or) - (void)setFrame:(CGRect)frame

并通过在这些方法中放置断点进行调试,以便您可以知道从哪里更新框架。

于 2014-04-21T09:42:15.473 回答