Skip to content

Instantly share code, notes, and snippets.

@overcyn
Last active October 24, 2017 06:06
Show Gist options
  • Select an option

  • Save overcyn/539725365f547272c87c49016799dd60 to your computer and use it in GitHub Desktop.

Select an option

Save overcyn/539725365f547272c87c49016799dd60 to your computer and use it in GitHub Desktop.
import UIKit
class CommentCountCell: UITableViewCell {
lazy var child: UIView = {
var child = UIView(frame: CGRect.zero)
child.translatesAutoresizingMaskIntoConstraints = false
child.backgroundColor = .red
return child
}()
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.addSubview(child)
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
var shouldSetupConstraints = true
override func updateConstraints() {
if shouldSetupConstraints {
child.topAnchor.constraint(equalTo: contentView.topAnchor).isActive = true
child.leftAnchor.constraint(equalTo: contentView.leftAnchor).isActive = true
child.rightAnchor.constraint(equalTo: contentView.rightAnchor).isActive = true
child.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true
child.heightAnchor.constraint(equalToConstant: 100).isActive = true
shouldSetupConstraints = false
}
super.updateConstraints()
}
}
@dmiedema
Copy link
Copy Markdown

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. 
(
    "<NSLayoutConstraint:0x1c4285fa0 V:|-(0)-[UIView:0x11be2bdc0]   (active, names: '|':UITableViewCellContentView:0x11be2b2d0 )>",
    "<NSLayoutConstraint:0x1c4286180 UIView:0x11be2bdc0.bottom == UITableViewCellContentView:0x11be2b2d0.bottom   (active)>",
    "<NSLayoutConstraint:0x1c42861d0 UIView:0x11be2bdc0.height == 100   (active)>",
    "<NSLayoutConstraint:0x1c4285d70 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x11be2b2d0.height == 99999   (active)>"
)```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment