objective c - Getting NSGeneric Exception while updating constraints programmatically? -


here code:

int x= 17; int y = 27; int width = 287; int height = 181; int mainview_height = 568; int x_spacer = 0; int y_spacer = 0; int width_spacer = 320; int height_spacer = 27;      uiview *view_spacer = [[uiview alloc]initwithframe:cgrectmake(x_spacer, y_spacer, width_spacer, height_spacer)];     [view_spacer setbackgroundcolor:[uicolor clearcolor]];     [view_spacer settranslatesautoresizingmaskintoconstraints:no];     [self.mainview addsubview:view_spacer];     uiview *view1 = [[uiview alloc]initwithframe:cgrectmake(x, y, width, height)];     [view1 setbackgroundcolor:[uicolor whitecolor]];     [view1 settranslatesautoresizingmaskintoconstraints:no];     [self.mainview addsubview:view1];      [view_spacer addconstraint:[nslayoutconstraint constraintwithitem:view_spacer attribute:nslayoutattributewidth     relatedby:nslayoutrelationequal toitem:view_spacer attribute:nslayoutattributeheight multiplier:width_spacer/height_spacer constant:0.0f]];     [self.mainview addconstraint:[nslayoutconstraint constraintwithitem:view_spacer attribute:nslayoutattributetop relatedby:nslayoutrelationequal toitem:self.mainview attribute:nslayoutattributetop multiplier:1 constant:0.0f]];     [self.mainview addconstraint:[nslayoutconstraint constraintwithitem:view_spacer attribute:nslayoutattributewidth     relatedby:nslayoutrelationequal toitem:self.mainview attribute:nslayoutattributeheight multiplier:width_spacer/mainview_height constant:0.0f]];     [self.mainview addconstraint:[nslayoutconstraint constraintwithitem:self.mainview attribute:nslayoutattributecenterx relatedby:nslayoutrelationequal toitem:view_spacer attribute:nslayoutattributecenterx multiplier:1 constant:0]];     [view_spacer addconstraint:[nslayoutconstraint constraintwithitem:view1 attribute:nslayoutattributetop relatedby:nslayoutrelationequal toitem:view_spacer attribute:nslayoutattributebottom multiplier:1 constant:0.0f]];     [view1 addconstraint:[nslayoutconstraint constraintwithitem:view1 attribute:nslayoutattributewidth                          relatedby:nslayoutrelationequal toitem:view1 attribute:nslayoutattributeheight                          multiplier:width/height constant:0.0f]];     [self.mainview addconstraint:[nslayoutconstraint constraintwithitem:view1 attribute:nslayoutattributewidth     relatedby:nslayoutrelationequal toitem:self.mainview attribute:nslayoutattributeheight                                                        multiplier:width/mainview_height constant:0.0f]];     [self.mainview addconstraint:[nslayoutconstraint constraintwithitem:self.mainview attribute:nslayoutattributecenterx relatedby:nslayoutrelationequal toitem:view1 attribute:nslayoutattributecenterx multiplier:1 constant:0]]; 

i got following error while updating auto layout constraints

the view hierarchy not prepared constraint: when added view, constraint's items must descendants of view (or view itself). crash if constraint needs resolved before view hierarchy assembled. break on -[uiview _viewhierarchyunpreparedforconstraint:] debug. 2015-07-18 12:54:02.469 landcorp cleaning app[2022:64687] view hierarchy unprepared constraint. constraint: container hierarchy: > view not found in container hierarchy: > view's superview: > 2015-07-18 12:54:02.472 landcorp cleaning app[2022:64687] * terminating app due uncaught exception 'nsgenericexception', reason: 'unable install constraint on view. constraint reference outside subtree of view? that's illegal. constraint: view:>' * first throw call stack: ( 0 corefoundation 0x000000010799dc65 exceptionpreprocess + 165 1 libobjc.a.dylib
0x0000000107636bb7 objc_exception_throw + 45 2 corefoundation
0x000000010799db9d +[nsexception raise:format:] + 205 3 foundation 0x00000001071c8479 -[nslayoutconstraint _addtoengine:integralizationadjustment:mutuallyexclusiveconstraints:] + 187 4 uikit 0x0000000108406786 -[uiview(uiconstraintbasedlayout) _layoutengine_didaddlayoutconstraint:roundingadjustment:mutuallyexclusiveconstraints:] + 411 5 uikit 0x0000000108406a14 -[uiview(uiconstraintbasedlayout) _trytoaddconstraintwithoutupdatingconstraintsarray:roundingadjustment:mutuallyexclusiveconstraints:] + 30 6 uikit 0x0000000108406b3c -[uiview(uiconstraintbasedlayout) _trytoaddconstraint:roundingadjustment:mutuallyexclusiveconstraints:] + 243 7 landcorp cleaning app 0x00000001070e7e47 -[inspectiondetails populatedataviews] + 2007 8 landcorp cleaning app 0x00000001070e748c -[inspectiondetails connection:didreceivedata:] + 1404 9 cfnetwork
0x00000001097dbd6c __65-[nsurlconnectioninternal _withconnectionanddelegate:onlyactive:]_block_invoke + 69 10 cfnetwork 0x00000001097dbd10 -[nsurlconnectioninternal _withconnectionanddelegate:onlyactive:] + 199 11 cfnetwork 0x00000001097dbe77 -[nsurlconnectioninternal _withactiveconnectionanddelegate:] + 48 12 cfnetwork 0x00000001097c6089 _zl30_nsurlconnectiondidreceivedatap16_cfurlconnectionpk8__cfdatalpkv + 79 13 cfnetwork 0x00000001096a85e0 ___zn27urlconnectionclient_classic29_delegate_didreceivedataarrayev_block_invoke + 302 14 cfnetwork 0x0000000109778a71 ___zn27urlconnectionclient_classic18_withdelegateasyncepkcu13block_pointerfvp16_cfurlconnectionpk33cfurlconnectionclientcurrent_vmaxe_block_invoke_2 + 273 15 cfnetwork 0x00000001096965d6 _zn19runloopblockcontext13_invoke_blockepkvpv + 72 16 corefoundation 0x00000001078a4354 cfarrayapplyfunction + 68 17 cfnetwork
0x0000000109696497 _zn19runloopblockcontext7performev + 133 18 cfnetwork 0x00000001096962d6 _zn17multiplexersource7performev + 256 19 cfnetwork 0x00000001096960ec _zn17multiplexersource8_performepv + 72 20 corefoundation 0x00000001078d1431 __cfrunloop_is_calling_out_to_a_source0_perform_function
+ 17 21 corefoundation 0x00000001078c72fd __cfrunloopdosources0 + 269 22 corefoundation 0x00000001078c6934 __cfrunlooprun + 868 23 corefoundation
0x00000001078c6366 cfrunlooprunspecific + 470 24 graphicsservices
0x000000010aec3a3e gseventrunmodal + 161 25 uikit
0x0000000107d968c0 uiapplicationmain + 1282 26 landcorp cleaning app 0x00000001070e897f main + 111 27 libdyld.dylib
0x0000000109f41145 start + 1 ) libc++abi.dylib: terminating uncaught exception of type nsexception


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -