简体   繁体   中英

Cannot get frame or center for elements inside UIView that is inside UITableView

I have an UITableView where first comes Table View Section following by UIView (bound to IBOutlet _myView) with some controls inside (eg UITextField, bound to IBOutlet _durationField). All this is done in the Storyboard. I want to move that _durationField dynamically, so I need to modify center or frame properties. However, this code inside viewDidLoad returns zero values:

CGRect durationRect = _durationField.frame;

whereas labels inside TableCell and _myView frame properties return real values, eg this doesn't return zeros:

CGRect viewRect = _myView.frame;

Also changing the frame property of _durationField doesn't reflect in the UI. Actually I get zero values for all controls inside _myView although they are properly bound to IBOutlet's in the code. Moreover, I can set _durationField.text in viewDidLoad and it works fine.

Any ideas? It looks like I'm missing something simple.

The first suggested solution with viewWillLayoutSubviews allows moving the element indeed but only after the view is rendered. So the user sees how it's moving. This is not a desirable behavior. I'd like to move the element dynamically before the view is rendered.

在viewDidLoad中,UI尚未布置,您应该将用于调整框架的代码移动到viewWillLayoutSubviews (确保首先调用超类实现)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM