objective c - View has changed when a TableView cell is selected for iOS -


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:

enter image description here

when cell selected:

enter image description here

many thanks!

ios 8+ solution (using autolayout):

add viewdidload:

self.tableview.estimatedrowheight = 44; self.tableview.rowheight = uitableviewautomaticdimension; 

and remove tableview:heightforrowatindexpath: method.


Comments