Ich möchte ein UITextField in eine UITableCell hinzufügen und legen Sie sowohl seine Breite und Höhe 100%;Swift Fehler erhalten, wenn AddConstraints für ein UITextField mit Visual Format Language
Mein SWIFT-Code:
nameTextField.translatesAutoresizingMaskIntoConstraints = false
addSubview(nameTextField)
let views = [
"name" : nameTextField
];
let widthLayoutConstraint = NSLayoutConstraint.constraintsWithVisualFormat("H:|-[name]-|", options: [], metrics: nil, views: views)
nameTextField.addConstraints(widthLayoutConstraint)
let heightLayoutConstraint = NSLayoutConstraint.constraintsWithVisualFormat("V:|-[name]-|", options: [], metrics: nil, views: views)
nameTextField.addConstraints(heightLayoutConstraint)
Ich habe die folgende Fehlermeldung, während die Tabelle zeigt:
2016-07-31 19:16:43.027 NOIB[40193:1889520] *** Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to install constraint on view. Does the constraint reference something from outside the subtree of the view? That's illegal. constraint:<NSLayoutConstraint:0x7ffbfa70f480 UITextField:0x7ffbfa41dff0.leading == NOIB.NameCell:0x7ffbfa41da10'NameCell'.leadingMargin> view:<UITextField: 0x7ffbfa41dff0; frame = (0 0; 0 0); text = ''; clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x7ffbfa41e5c0>>'