1

What is the proper way to remove NSIBPrototypingLayoutConstraints from UITableViewCell subviews and add my own constraints without seeing error messages in the simulator log?

For example, I want to dynamically change the size of a UILabel inside a UITableViewCell by adding a width constraint. I don't even know if this the preferred method of doing this. Is there some way for me to find the constraint and update that directly?

coolio
  • 409
  • 4
  • 12

1 Answers1

2

You can remove all of the constraints for an object, then add back in the ones you want.

To remove them:

[yourView removeConstraints:yourView.constraints];

Then you can manually add your own constraints. (here is a more detailed link on adding view width constraints)

To just modify the existing constraints:

for(NSLayoutConstraint *constraint in yourView.constraints) {
    //you can inspect these to see if their .firstAttribute or .secondAttribute correspond to the type of NSLayoutAttribute you are looking for.
 }
Community
  • 1
  • 1
HalR
  • 11,411
  • 5
  • 48
  • 80
  • Are NSIBPrototypingLayoutConstraints generated by IB not able to be seen in this way? When I inspect views.constraints inside the tableview cell and the cell.constraints, they seem to be blank. – coolio Oct 06 '13 at 23:10
  • Did you look at this answer? It has a few ideas on autolayout options. Also, if you remove all the visible constraints, you should be able to override ib one with your manually entered ones. – HalR Oct 07 '13 at 04:45