Error404 Error404 - 11 months ago 50
Swift Question

"The constraint outlet from the TableViewController to the NSLayoutConstraint is invalid." error

I am trying to create an

to modify a constraint of an
that is inside of an
but I am getting the following error:

The constraint outlet from the CustomTableViewController to the NSLayoutConstraint is invalid. Outlets cannot be connected to repeating content.

I guess from the error that it is because it is being repeated each time in each row but I am not able to solve this.

I have searched a lot and related errors did not solve anything to me because most of them suggest if I have more than one
to the same constraint. I have checked it but I do not have it duplicated (of course it is going to be more than one constraint when rows are more than 1).

I do not think it could be relevant for this issue but I am using Swift 3.0.

How can I solve this? I am totally stuck.

Thanks in advance!

Answer Source

Declare a UITableViewCell subclass. In the declaration, declare an outlet property whose value is an NSLayoutConstraint. In the storyboard, select the prototype cell and set its class to be your subclass. Draw the outlet between the cell and the constraint. In your cellForRowAt implementation, cast the dequeued cell to your subclass. Now you can refer to the constraint property.