Activate restrictions in uitableviewcell not working for the first time

I have the following hierarchy in a UITableViewCell.

UITableViewCell
-UIView1
--UILabel1
-UIView2
--UILabel2

I want UIView1 to be hidden in height when UILabel1 has no text. For this, I took a height limit of 0 for UIView1 with the initially deleted state.

Now in cellForRowAtIndexPath I activate this restriction when I check that the row for Label1 is empty or not?

This does not work for the first load of the cell, and when I look at the table, this restriction applies. I use [cell layoutIfNeeded] after activating the restrictions, but it does not seem to work here for the first load.

How can I crack this problem?

+5
source share
3

, .

layoutSubviews() UITableViewCell.

, !

+1

, , , - :

, layoutSubviews

override func layoutSubviews() {
    super.layoutSubviews()

    //update your constraints
    //NOTE: there no need to call layoutIfNeeded 
}
0

2 1000 , , layoutIfNeeded

0

Source: https://habr.com/ru/post/1650546/


All Articles