Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

activate constraints in uitableviewcell not working first time

I have following hierarchy in UITableViewCell.

UITableViewCell
-UIView1
--UILabel1
-UIView2
--UILabel2

I want UIView1 to be hidden by height when UILabel1 have no text. For that I have taken a height constraint of 0 for UIView1 with initially uninstalled state.

Now in cellForRowAtIndexPath I am activating this constraint when i check the string for Label1 is empty or not?

This is not working for the first load of the cell and when i scroll through the tableview this constraint is applied. I am using [cell layoutIfNeeded] after activating constraints but it seems not to be working here for first load.

How can i crack this issue?

like image 767
Bhavesh Avatar asked Nov 09 '22 11:11

Bhavesh


1 Answers

I managed to solve this by creating two constraints and changing their priorities in runtime.

The constraint priority happens in layoutSubviews() of subclassed UITableViewCell.

Hope this helps !

like image 123
Maciej Stramski Avatar answered Nov 15 '22 11:11

Maciej Stramski