ios - When I add autolayout, the views disapear -


i have 1 label , 1 uicollectionview in overall view. i'm trying them image below:

i can't use storyboard apply auto-layout, have programmatically, , i'm having difficulty doing that. here have:

cgrect collectionviewframe = cgrectmake(0, 20, self.bounds.size.width, self.bounds.size.height - 20); _datescollectionview = [[uicollectionview alloc] initwithframe:collectionviewframe collectionviewlayout:collectionviewlayout];  _labeltochange = [[uilabel alloc] initwithframe:cgrectmake(0, 0, self.bounds.size.width, 20)];  [_labeltochange settranslatesautoresizingmaskintoconstraints:no]; [datescollectionview settranslatesautoresizingmaskintoconstraints:no];  [self addconstraints:[nslayoutconstraint constraintswithvisualformat:@"[_labeltochange]-[_datescollectionview]" options:0 metrics:nil views:nsdictionaryofvariablebindings(_labeltochange, _datescollectionview)]];  [self addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:[_labeltochange]|" options:0 metrics:nil views:nsdictionaryofvariablebindings(_labeltochange)]]; [self addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:|[_labeltochange]|" options:0 metrics:nil views:nsdictionaryofvariablebindings(_labeltochange)]];  [self addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:|[_datescollectionview]|" options:0 metrics:nil views:nsdictionaryofvariablebindings(_datescollectionview)]]; [self addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:[_datescollectionview]|"options:0 metrics:nil views:nsdictionaryofvariablebindings(_datescollectionview)]]; 

when run on simulator, don't see of view's, , following error:

probably @ 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)  (     "<nslayoutconstraint:0x7fa080d801b0 h:|-(0)-[didatepicker:0x7fa080d7f9a0]   (names: '|':uitableviewcellcontentview:0x7fa080d7f360 )>",     "<nslayoutconstraint:0x7fa080d80250 h:[didatepicker:0x7fa080d7f9a0]-(0)-|   (names: '|':uitableviewcellcontentview:0x7fa080d7f360 )>",     "<nslayoutconstraint:0x7fa080da9120 h:[uilabel:0x7fa080da8350]-(0)-[uicollectionview:0x7fa081159000]>",     "<nslayoutconstraint:0x7fa080daa7e0 h:[uilabel:0x7fa080da8350]-(0)-|   (names: '|':didatepicker:0x7fa080d7f9a0 )>",     "<nslayoutconstraint:0x7fa080daab50 h:|-(0)-[uicollectionview:0x7fa081159000]   (names: '|':didatepicker:0x7fa080d7f9a0 )>",     "<nslayoutconstraint:0x7fa080db70c0 'fittingsizehtarget' h:[uitableviewcellcontentview:0x7fa080d7f360(375)]>" )  attempt recover breaking constraint  <nslayoutconstraint:0x7fa080da9120 h:[uilabel:0x7fa080da8350]-(0)-[uicollectionview:0x7fa081159000]> 

what doing wrong, , can fix it?

this line ambigious:

[self addconstraints:[nslayoutconstraint constraintswithvisualformat:@"[_labeltochange]-[_datescollectionview]" options:0 metrics:nil views:nsdictionaryofvariablebindings(_labeltochange, _datescollectionview)]]; 

and don't have width or height information defined views. autolayout doesn't have enough information layout view.

try instead:

nsdictionary *dict = nsdictionaryofvariablebindings(_labeltochange, _datescollectionview);  [self addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:|-0-[_labeltochange(80)]-0-[_datescollectionview]-0-|" options:0 metrics:nil views:dict]];  [self addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:|-0-[_labeltochange]-0-|" options:0 metrics:nil views:dict]];  [self addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:|-0-[_datescollectionview]-0-|" options:0 metrics:nil views:dict]]; 

what i've done here is, have defined label 80 pixels tall , collectionview takes rest of height of superview.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -