ios - heightForRowAtIndexPath - how to default to maximum element height of cell -
i have been developing couple of tableviews now. feel wasting time implementing heightforrowatindexpath
time. there way default height maximum element y
value of row, constructed cellforrowatindexpath
adding default padding?
i asking myself, why method not in default ios , developers may override method, if cellforrowatindexpath
memory consuming.
the following code show how implement our call -heightforrowatindexpath
:
- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath; { nsstring *text = [items objectatindex:[indexpath row]]; cgsize constraint = cgsizemake(cell_content_width - (cell_content_margin * 2), 20000.0f); cgsize size = [text sizewithfont:[uifont systemfontofsize:font_size] constrainedtosize:constraint linebreakmode:uilinebreakmodewordwrap]; cgfloat height = max(size.height, 44.0f); return height + (cell_content_margin * 2); }
Comments
Post a Comment