iphone - Mapping memory address of unsatisfyable NSLayoutConstraints to UI controls -
i appreciate xcode catch unsatifyable nslayoutconstraints
, gives information it, not know how take memory addresses of controls/constraints , map actual controls have problem.
my app large (around 20 screens), large uiviewcontrollers several child view controller within them. uitableviews custom cells , uicollectionviews custom cells. i'm having hell of time tacking down cause of error (which happens on landscape rotation)
here information console:
2013-05-02 11:18:53.225 smile[7519:c07] unable simultaneously satisfy constraints. @ least 1 of constraints in following list 1 don't want. try this: (1) @ each constraint , try figure out don't expect; (2) find code added unwanted constraint or constraints , fix it. (note: if you're seeing nsautoresizingmasklayoutconstraints don't understand, refer documentation uiview property translatesautoresizingmaskintoconstraints) ( "<nsautoresizingmasklayoutconstraint:0x16083b60 h=-&- v=-&- uiview:0xa5a1d00.width == uiwindow:0xa09eee0.width>", "<nslayoutconstraint:0xa5a2180 v:[uiview:0xa59f160]-(954)-| (names: '|':uiview:0xa5a1d00 )>", "<nslayoutconstraint:0xa5a2140 v:|-(0)-[uiview:0xa59f160] (names: '|':uiview:0xa5a1d00 )>", "<nsautoresizingmasklayoutconstraint:0xa593340 h=--- v=--- h:[uiwindow:0xa09eee0(768)]>" ) attempt recover breaking constraint <nslayoutconstraint:0xa5a2180 v:[uiview:0xa59f160]-(954)-| (names: '|':uiview:0xa5a1d00 )> break on objc_exception_throw catch in debugger. methods in uiconstraintbasedlayoutdebugging category on uiview listed in <uikit/uiview.h> may helpful.
as can see, there memory addresses listed. pasting watch window's search bar doesn't reveal much. sifting though thread , queue call stacks, disassembled code on breakpoint (exception breakpoint).
the short answer not really, os x has identifier property can set on view used nslayoutconstraint identify views doesn't exist on ios yet.
however there 'work around' implement similar on ios isn't pretty. first have establish name each view, accomplished in uiview category. have update output nslayoutconstraint description use new tags.
@interface nslayoutconstraint (nametags) - (nsstring *)asciiartdescription; @end @interface uiview (nametags) @property (nonatomic, strong) nsstring *nametag; @end
then provide implementation follows change output of nslayout
#import <objc/objc-runtime.h> static const char nametag_key; @implementation nslayoutconstraint (nametags) - (nsstring *)description { nsmutablestring *mydescription = [nsmutablestring stringwithformat:@"%@, ", [self asciiartdescription]]; uiview *firstview = (uiview *)[self firstitem]; if (firstview) { [mydescription appendformat:@"first view: 0x%0x: %@, ", (int)firstview, firstview.nametag]; } uiview *secondview = (uiview *)[self seconditem]; if (secondview) { [mydescription appendformat:@"second view: 0x%0x: %@", (int)secondview, secondview.nametag]; } return mydescription; } @end @implementation uiview (nametags) - (id) nametag { return objc_getassociatedobject(self, (void *) &nametag_key); } - (void)setnametag:(nsstring *) thenametag { objc_setassociatedobject(self, (void *) &nametag_key, thenametag, objc_association_retain_nonatomic); } @end
then able set names on views so
self.view.nametag = @"myusefulname";
or define them in ib
finally when ever dump constraints names provided in output.
"v:|-(202)-[uiview:0x75606f0], first view: 0x75606f0: blue view, second view: 0x7560bd0: (null)", "v:[uiview:0x75606f0]-(72)-|, first view: 0x7560bd0: (null), second view: 0x75606f0: blue view", "v:[uiview:0x7560bd0(548)], first view: 0x7560bd0: (null), "
you should use code in debug builds, don't ship in app because accesses private [nslayoutconstraint asciiartdescription] method.
Comments
Post a Comment