davdroman / Bohr

Settings screen composing framework
MIT License
1.26k stars 83 forks source link

NSLayoutConstaint Issue with UITextField - BOTextTableViewCell #6

Closed firecast closed 9 years ago

firecast commented 9 years ago

Steps to recreate:

  1. Add another BOTimeTableViewCell in the Section 2 of demo example.
  2. Tap to open the Cell Everything works perfectly
  3. Tap to close the pickerView Oops!!
Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7feaa363edb0 H:[UITableViewLabel:0x7feaa3631b90'Text']-(15)-[UITextField:0x7feaa363b070](LTR)>",
    "<NSLayoutConstraint:0x7feaa363ee00 UITextField:0x7feaa363b070.right == UITableViewCellContentView:0x7feaa3631a50.rightMargin>",
    "<NSAutoresizingMaskLayoutConstraint:0x7feaa37ddfc0 h=--& v=--& UITableViewLabel:0x7feaa3631b90'Text'.midX == + 187.5>",
    "<NSAutoresizingMaskLayoutConstraint:0x7feaa37de010 h=--& v=--& H:[UITableViewLabel:0x7feaa3631b90'Text'(343)]>",
    "<NSLayoutConstraint:0x7feaa37f3c00 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x7feaa3631a50(375)]>",
    "<NSAutoresizingMaskLayoutConstraint:0x7feaa37ef590 h=--& v=--& 'UIView-Encapsulated-Layout-Left' H:|-(0)-[UITableViewCellContentView:0x7feaa3631a50]   (Names: '|':BOTextTableViewCell:0x7feaa3631040 )>"
)

This happens when a pickerView closes and the BOTimeTableViewCell has been dequeued. So when the TableViewcreates it again it throws the above error.

davdroman commented 9 years ago

Does it have any impact on the UI itself (hiding elements, bad positioning...)?

firecast commented 9 years ago

Have only tested it iPhone6 on landscape and portrait mode. Seems to be working fine. But the error also mentions Will attempt to recover by breaking constraint <NSLayoutConstraint:0x7fcbaa61e9e0 H:[UITableViewLabel:0x7fcbaa541250'Text']-(15)-[UITextField:0x7fcbaa61c7e0](LTR)> so might cause layout issues somewhere

davdroman commented 9 years ago

Don't worry about it. The warning refers to the cell's textLabel, which doesn't have any constraints attached to it (this is an internal, annoying default behavior Apple set up for its cells). I had to hack a bit around layoutSubviews method in order for constraints to work.

TL;DR that warning is totally fine.