[英]Programmatic Autolayout changes inside UITableViewCell updated only after orientation change
I have a UITableView
with automatic row heights and a custom UITableViewCell
. 我有一个UITableView
具有自动行高和自定义UITableViewCell
。 Inside the UITableViewCell
, I first add some UIButton
s with programmatic Autolayout constraints. 在UITableViewCell
内部,我首先添加一些带有程序化Autolayout约束的UIButton
。 They are positioned perfectly as I want. 它们完全按照我的要求定位。 Then, after 3 seconds ( NSTimer
), I remove all those UIButton
s and re-add a different number of them again. 然后,在3秒后( NSTimer
),我删除所有那些UIButton
并再次重新添加不同数量的UIButton
。 (For eg initially I have 4 UIButtons
, after 3 seconds, I remove those 4 UIButton
s and add 3 different ones. (例如,最初我有4个UIButtons
,3秒后,我删除了4个UIButton
并添加了3个不同的UIButton
。
Initially : 最初 :
Post rotate: 后旋转:
Why is this happening? 为什么会这样? I don't see any Autolayout warnings. 我没有看到任何Autolayout警告。 Also, after an orientation change, everything is correctly positioned. 此外,在方向更改后,一切都正确定位。 What is it that requires an orientation change? 什么是需要改变方向? How can I force this manually?(reloading the tableview just for this seems too much to do) 我怎样才能手动强制执行此操作?(仅为此重新加载tableview似乎太多了)
PS: I tried using setNeedsUpdateConstraints
, layoutIfNeeded
, layoutSubviews
but to no avail. PS:我尝试使用setNeedsUpdateConstraints
, layoutIfNeeded
, layoutSubviews
但无济于事。
Here's the UITableViewCell
code: http://pastebin.com/TcHUXgDU . 这是UITableViewCell
代码: http : //pastebin.com/TcHUXgDU 。 (Added a pastebin to not pollute this space) But basically, there's a configure:
method that I have inside my tableview subclass which I call in the cellForRowAtIndexPath
of its containing UITableView
. (添加了一个不污染这个空间的pastebin)但基本上,我在tableview子类中有一个configure:
方法,我在其包含UITableView
的cellForRowAtIndexPath
中调用它。 This method adds those constraints. 此方法添加了这些约束。 Also, after the timer fires, the same code is called (in another function) except that the number of items I add are different from the initial number of items. 此外,在计时器触发后,调用相同的代码(在另一个函数中),除了我添加的项目数与初始项目数不同。
This is my UITableViewCell
layout: (Only top,bottom,leading,trailing constraints have been added to the UIView "Outerview") 这是我的UITableViewCell
布局:(只有顶部,底部,前导,尾随约束已添加到UIView“Outerview”)
您需要重新加载UITableView,这将重新计算单元格的高度
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.