i'm trying create layout constraint between tableview , view controller's view. tableview directly inside main view.
here:
let leftconstant = cgfloat(250.0) let topconstraint = nslayoutconstraint(item: menutableview, attribute: .top, relatedby: .equal, toitem: self.toplayoutguide, attribute: .bottom, multiplier: 1, constant: 0.0) let leftconstraint = nslayoutconstraint(item: menutableview, attribute: .leadingmargin, relatedby: .equal, toitem: view, attribute: .leadingmargin, multiplier: 1, constant: -leftconstant) let bottomconstraint = nslayoutconstraint(item: menutableview, attribute: .bottom, relatedby: .equal, toitem: self.bottomlayoutguide, attribute: .top, multiplier: 1, constant: 0.0) let widthconstraint = nslayoutconstraint(item: menutableview, attribute: .width, relatedby: .equal, toitem: nil, attribute: .notanattribute, multiplier: 0, constant: leftconstant) let verticalcenterconstraint = nslayoutconstraint(item: menutableview, attribute: .centerx, relatedby: .equal, toitem: view, attribute: .centerx, multiplier: 1, constant: 0.0) menutableview.addconstraints([topconstraint, leftconstraint, bottomconstraint, widthconstraint, verticalcenterconstraint]) ...and i'm getting error:
terminating app due uncaught exception 'nsgenericexception', reason: 'unable install constraint on view. constraint reference outside subtree of view? that's illegal. constraint:<nslayoutconstraint:0x16d18490 v:[_uilayoutguide:0x16d24de0]-(0)-[uitableview:0x172a3800]> view:<uitableview: 0x172a3800; frame = (0 0; 250 568); clipstobounds = yes; autoresize = rm+bm; gesturerecognizers = <nsarray: 0x16e23190>; layer = <calayer: 0x16e24e20>; contentoffset: {0, 0}; contentsize: {250, 74}>'
add constraint of menutableview itself, replace
menutableview.addconstraints([topconstraint, leftconstraint, bottomconstraint, widthconstraint, verticalcenterconstraint]) with
menutableview.addconstraint(widthconstraint) and add these constraint view
view.addconstraints([topconstraint, leftconstraint, bottomconstraint]) because view holds constraint must ancestor of views constraint involves
**and must choose either .leading or .centerx, otherwise unable simultaneously satisfy constraints.
Comments
Post a Comment