i create custom table view cell using autolayout picture below 
when app launch, every thing fine. when scroll tableview or select view, cell's layout changed. whats happen?
code:
- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath{ tableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellident]; [cell.textlabel settext: texttoshow]; cell.bounds = cgrectmake(0.0f, 0.0f, cgrectgetwidth(tableview.bounds), cgrectgetheight(cell.bounds)); [cell setneedslayout]; [cell layoutifneeded]; cgsize fitsize = [cell.contentview systemlayoutsizefittingsize:uilayoutfittingcompressedsize]; return fitsize.height; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section{ return 3; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{ tableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellident]; [cell.textlabel settext:texttoshow]; return cell; } run app:

when cell selected:

many thanks!
ios 8+ solution (using autolayout):
add viewdidload:
self.tableview.estimatedrowheight = 44; self.tableview.rowheight = uitableviewautomaticdimension; and remove tableview:heightforrowatindexpath: method.
Comments
Post a Comment