ios - UITableView dynamic height cannot satisfy constraints -
i'm trying use autolayout dynamically determine height of table cells using tutorial http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout
the problem is, i'm getting these weird automatic constraints set dimensions simulated metrics of custom cell. have done lot of autolayout, , thought simulated metrics weren't supposed affect actual app @ runtime. did change in new sdk?
anyway, here method i've been messing with...
- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath { static jmsocialfeedtableviewcell *sizingcell = nil; static dispatch_once_t oncetoken; dispatch_once(&oncetoken, ^{ sizingcell = [self.tableview dequeuereusablecellwithidentifier:@"cell"]; }); [self configurecell:sizingcell forindexpath:indexpath]; //[sizingcell.contentview addconstraint:[nslayoutconstraint constraintwithitem:sizingcell.contentview attribute:nslayoutattributewidth relatedby:nslayoutrelationequal toitem:nil attribute:nslayoutattributewidth multiplier:0 constant:self.tableview.frame.size.width]]; [sizingcell setneedslayout]; [sizingcell layoutifneeded]; //cgsize size = [sizingcell.contentview sizethatfits:cgsizemake(self.tableview.frame.size.width, cgfloat_max)]; cgsize size = [sizingcell.contentview systemlayoutsizefittingsize:uilayoutfittingcompressedsize]; return size.height + 1.0f; // add 1.0f cell separator height }
the commented out lines different things trying. simulated metrics 300 x 389. sizethatfits method returns size though table view 320 wide. systemlayoutsizefittingsize returns 400 x 489 whatever reason. in these cases, easy see why i'm getting unsatisfiable constraints, height should 409 (+1.0f seperator maybe. i've been trying , without too).
i'm not setting other constraints in code, if try adding 1 have commented in code above i'm getting weird constraint...
"<nslayoutconstraint:0x1701ebf0 'uiview-encapsulated-layout-width' h:[uitableviewcellcontentview:0x1705a310(300)]>"
i don't know why number 300 keeps showing up. thought simulated metrics supposed gone once view laid out.
sorry if question isn't 100% clear. guess i'm confused on few points. i'm trying autolayout determine proper height of cell given cell's width should equal width of table view (which 320 on device i'm testing on).
Comments
Post a Comment