ios - Error using activateConstraints on a collection of Container View constraints -


in ios 8 app using size classes, ipad have different layout in portrait , landscape have iboutletcollection each orientation activate , deactivate. has worked great until introduction of container view.

i'm adding new vc separate tab item in iphone version, embed ipad layout using container view. i'll focus on 1 size class, regularregular. container view has 4 constraints: trailing, leading, top, , bottom. when run app, looks fine (in single orientation).

now, when add these 4 constraints iboutletcollection, activateconstraints message fails following error message:

*** terminating app due uncaught exception 'nsgenericexception', reason: 'unable activate constraint items ; layer = ; contentoffset: {0, 0}; contentsize: {460, 78}> , > because have no common ancestor. constraint reference items in different view hierarchies? that's illegal.'

the constraints don't reference items in different view hierarchies. top, bottom, , leading in relation view in vc's view. trailing in relation stepper in vc's view. they're @ same hierarchal level knowledge.

when in debug, can see constraint starts off active property nil. appears normal (the non-container constraints started off same prior them being set yes). checked loop setting active property.

is there i'm doing wrong constraints on container view? constraints on container view somehow special because on container view? i've tried finding answer myself, can't seem find in regard issue i'm having.

any appreciated.

4/10 edit provide pictures & code. note @ time i've broken out container constraints separate array can deal them on own.

in image below, container's leading, top, , bottom constraints in relation view right of container. trailing constraint in relation stepper above it. vc layout

related code:

@property (strong, nonatomic) iboutletcollection(nslayoutconstraint) nsarray *regularanyconstraints; @property (strong, nonatomic) iboutletcollection(nslayoutconstraint) nsarray *regularanycontainerconstraints;  @property (strong, nonatomic) iboutletcollection(nslayoutconstraint) nsarray *anyregularconstraints; @property (strong, nonatomic) iboutletcollection(nslayoutconstraint) nsarray *anyregularcontainerconstraints; 

these constraints in _anyregularcontainerconstraints array: _anyregularcontainerconstraints

[nslayoutconstraint deactivateconstraints:_regularanyconstraints]; [nslayoutconstraint activateconstraints:_anyregularconstraints];  [nslayoutconstraint deactivateconstraints:_anyregularcontainerconstraints]; [nslayoutconstraint activateconstraints:_anyregularcontainerconstraints]; 

when in debug, can see constraint starts off active property nil

that remark makes me wonder whether might misinterpreting activateconstraints , deactivateconstraints do. despite names, , despite misleading entry in documentation, add , remove constraints. thus, instead of confusing these commands, suggest might better call addconstraints , removeconstraints directly. advantage of doing is:

  • these latter uiview methods, in conscious control of view constraints added to.

  • when removing, clear on responsibility retain removed constraints if want use them again later.

i realize doesn't answer question directly, didn't provide enough info (you didn't show code calls activateconstraints , deactivateconstraints, didn't show diagram of view controller , view hierarchies, etc.) not entirely clear going wrong. instead, i'm trying reorient thinking try work out details of problem.


Popular posts from this blog