Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a constraint already exists inside a view?

I'm using auto layout for my tableView and for every cell in it, I create some constraints programmatically.

In order to avoid to delete ALL the constraints every time, I would like to know if there is a way to loop view.constraints() and if there is a constraint such as H:|-view-|, I delete it.

Is it possible?

like image 447
Nico Avatar asked Apr 09 '15 08:04

Nico


1 Answers

You would need to use variables (or an array) to hold those constraints that match what you want and then loop the view.constraints() to remove them. When you use the visual format, whatever you create is converted into multiple constraints.

Another method to use is to go through the constraints and check the constraint properties such as firstItem and secondItem, relation, etc. to match what you want.

like image 151
Schemetrical Avatar answered Sep 23 '22 18:09

Schemetrical