簡體   English   中英

setNeedsDisplay不會更改UITableView的中心

[英]setNeedsDisplay doesn't change UITableView's center

通過IB添加了UITableView 我試圖以編程方式更改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

正如您在日志中看到的那樣, UITableViewY軸值發生了變化,但是在我調用setNeedsDisplay時 ,我看不到任何視覺效果或UITableView正在重繪,而且我也不明白為什么Y軸值會還原每次我通過單擊UIButton調用此代碼時,返回788。

嘗試使用[[_prescribingDoctorTableView superview] setNeedsLayout]而不是[_prescribingDoctorTableView setNeedsDisplay]來布局子視圖。

如果這不起作用,請子類化您的視圖並覆蓋方法,

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

並通過在這些方法中放置斷點進行調試,以便您可以從中更新框架。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM