ios - NSAutoresizingMaskLayoutConstraint error when UITableViewHeaderFooterView is reused -
i'm getting following error after call insertsections:withrowanimation:
, endupdates
. error concerns autolayout in custom uitableviewheaderfooterview
when header reused dequeuereusableheaderfooterviewwithidentifier:
. first time works fine no errors.
unable simultaneously satisfy constraints. ... ( "<nslayoutconstraint:0x10b77f9f0 v:|-(8)-[uiview:0x10b77d0f0] (names: '|':wybdetailheaderview:0x10b77e620 )>", "<nsautoresizingmasklayoutconstraint:0x10b77cac0 h=--& v=--& v:[wybdetailheaderview:0x10b77e620(0)]>", "<nslayoutconstraint:0x10b77fa40 v:[uiview:0x10b77d0f0]-(>=4)-| (names: '|':wybdetailheaderview:0x10b77e620 )>" ) attempt recover breaking constraint <nslayoutconstraint:0x10b77fa40 v:[uiview:0x10b77d0f0]-(>=4)-| (names: '|':wybdetailheaderview:0x10b77e620 )>
there similar error horizontal constraints. problem nsautoresizingmasklayoutconstraint
appears both width , height set zero. however, once animation completes header layout correct , looks fine.
i have followed advice in related question no luck: uitableviewheaderfooterview subclass auto layout , section reloading won't work together
has encountered similar before?
is there can avoid warning?
this implementation in uitableview
:
- (uiview *)tableview:(uitableview *)tableview viewforheaderinsection:(nsinteger)section { wybdetailheaderview *header = [tableview dequeuereusableheaderfooterviewwithidentifier:@"wyb"]; [header setupwithtitle:@"title" subtitle:@"subtitle"]; return header; }
and implementation of wybdetailheaderview (it uses nib register registernib:forheaderfooterviewreuseidentifier:
):
- (void)setupwithtitle:(nsstring *)title subtitle:(nsstring *)subtitle { // set labels. self.titlelabel.text = title.uppercasestring; self.subtitlelabel.text = subtitle; // clear image. self.headerimageview.image = nil; self.emptyimage = no; // mark layout update. [self setneedsupdateconstraints]; [self setneedslayout]; } - (void)prepareforreuse { self.prototype = no; self.emptyimage = no; } - (void)updateconstraints { // see if there image. if (self.emptyimage || self.headerimageview.image) { self.imagewidthconstraint.constant = 20; self.imageheightconstraint.constant = 20; self.imagetitlespaceconstraint.constant = 8; } else { self.imagewidthconstraint.constant = 0; self.imageheightconstraint.constant = 0; self.imagetitlespaceconstraint.constant = 0; } [super updateconstraints]; } - (void)layoutsubviews { [super layoutsubviews]; self.titlelabel.preferredmaxlayoutwidth = cgrectgetwidth(self.titlelabel.frame); self.subtitlelabel.preferredmaxlayoutwidth = cgrectgetwidth(self.subtitlelabel.frame); [super layoutsubviews]; }
i had similar error , making use of estimatedheightforrowatindexpath caused it.
Comments
Post a Comment