Frame change of table view cell's subview won't take place until view did appear

扶醉桌前 提交于 2019-12-13 01:25:56

问题


I want to change a UITableViewCell's subview when it is being setup in the cellForRowAtIndexPath with the following code:

cellSubView.center = CGPointZero

Printing out the frame's coordinates shows, that the frame updates successfully, however the view is still displayed in the position that was given in the interface builder.

Overriding the viewDidAppear function with the following code would resolve this issue:

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    self.tableView.reloadData()
}

But this will result in blinking: the table view already did appear when I change one of its cells' subview's position.

How is it possible to change the frame before the view did appear?


回答1:


If you used autoLayout check if it's creating the constraints automatically. If yes, then you can change the constants of these constraints instead. If you are not using autoLayout, call layoutIfNeeded and see if that changes anything. My bet though is on autoLayout creating constraints automatically.



来源:https://stackoverflow.com/questions/30523776/frame-change-of-table-view-cells-subview-wont-take-place-until-view-did-appear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!