1

I am trying to create an @IBOutlet to modify a constraint of an UILabel that is inside of an UITableViewCell 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 @IBOutlet 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!

Francisco Romero
  • 12,787
  • 22
  • 92
  • 167

1 Answers1

3

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.

Janmenjaya
  • 4,149
  • 1
  • 23
  • 43
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 1
    You are very welcome. Your question was very well asked: you explored the matter thoroughly and had an excellent grasp of the problem before formulating the question. – matt Oct 21 '16 at 12:46