简体   繁体   中英

Programmatic Autolayout changes inside UITableViewCell updated only after orientation change

I have a UITableView with automatic row heights and a custom UITableViewCell . Inside the UITableViewCell , I first add some UIButton s with programmatic Autolayout constraints. 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. (For eg initially I have 4 UIButtons , after 3 seconds, I remove those 4 UIButton s and add 3 different ones.

Initially :

原来 After 3 seconds :

3秒后

Post rotate:

在此输入图像描述

Why is this happening? I don't see any Autolayout warnings. 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)

PS: I tried using setNeedsUpdateConstraints , layoutIfNeeded , layoutSubviews but to no avail.

Here's the UITableViewCell code: 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 . 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布局

您需要重新加载UITableView,这将重新计算单元格的高度

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