ios - AutoLayout in UITableview with dynamic cell height -
for dynamic height of table view cell take reference link. using auto layout in uitableview dynamic cell layouts & variable row heights
here code of tableview data source , delegate methods
-(nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section; { return arrtemp. count; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier=@"autolayoutcell"; autolayouttableviewcell *cell=(autolayouttableviewcell *)[tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell==nil) { (id currentobject in [[nsbundle mainbundle] loadnibnamed:@"autolayouttableviewcell" owner:self options:nil]) { if ([currentobject iskindofclass:[uitableviewcell class]]) { cell = (autolayouttableviewcell *)currentobject; break; } } } cell.iblbllineno.text=[nsstring stringwithformat:@"line:%i",indexpath.row]; cell.iblbllinetext.text=[arrtemp objectatindex:indexpath.row]; [cell setneedsupdateconstraints]; [cell updateconstraintsifneeded]; cgsize expectedlinelabelsize = [cell.iblbllinetext.text sizewithfont:cell.iblbllinetext.font constrainedtosize:cgsizemake(280, 1000) linebreakmode:nslinebreakbytruncatingtail]; cell.iblbllinetext.numberoflines=expectedlinelabelsize.height/17; cgrect frmlbl=cell.iblbllinetext.frame; frmlbl.size.height=expectedlinelabelsize.height; cell.iblbllinetext.frame=frmlbl; return cell; } - (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath { autolayouttableviewcell *cell = (autolayouttableviewcell *)[ibtblautolayoutexample cellforrowatindexpath:indexpath]; cell.iblbllineno.text=[nsstring stringwithformat:@"line:%i",indexpath.row]; cell.iblbllinetext.text=[arrtemp objectatindex:indexpath.row]; [cell setneedsupdateconstraints]; [cell updateconstraintsifneeded]; cgsize expectedlinelabelsize = [cell.linelabel.text sizewithfont:cell.linelabel.font constrainedtosize:cgsizemake(280, 1000) linebreakmode:nslinebreakbywordwrapping]; cell.iblbllinetext.numberoflines=expectedlinelabelsize.height/17; cgrect frmlbl=cell.iblbllinetext.frame; frmlbl.size.height=expectedlinelabelsize.height; cell.iblbllinetext.frame=frmlbl; cgfloat height = [cell.contentview systemlayoutsizefittingsize:uilayoutfittingcompressedsize].height; height += 1.0f; return height; } - (cgfloat)tableview:(uitableview *)tableview estimatedheightforrowatindexpath:(nsindexpath *)indexpath { autolayouttableviewcell *cell = (autolayouttableviewcell *)[ibtblautolayoutexample cellforrowatindexpath:indexpath]; cgsize expectedlinelabelsize = [cell.iblbllinetext.text sizewithfont:cell.iblbllinetext.font constrainedtosize:cgsizemake(280, 1000) linebreakmode:nslinebreakbytruncatingtail]; return expectedlinelabelsize.height; }
i have 2 questions :
my issue error
exe_bad_excess
near lineautolayouttableviewcell *cell = (autolayouttableviewcell *)[ibtblautolayoutexample cellforrowatindexpath:indexpath];
in
heightforrowatindexpath
,estimatedheightforrowatindexpath
.why have write label text in both
cellforrowatindexpath
,heightforrowatindexpath
?
also, missing needed achieve dynamic height cell?
Comments
Post a Comment