ios - cell.contentView systemLayoutSizeFittingSize: does not work for dynamic height tableview -


i tried use autolayout in custom uitableviewcell , tried implement dynamic height according topic

using auto layout in uitableview dynamic cell layouts & variable row heights

but cell created xib file. method different here code in heightforrowatindexpath

   -(cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath   {  mydataitem *item= [[data items] objectatindex:[indexpath row]];       customcell *cell = [self.offscreencells objectforkey:@"customcell"];     if (!cell) {         cell =  [customcell alloc] init];         [self.offscreencells setobject:cell forkey:@"customcell"];       }          [cell.commentview settext:item.comment];      [cell.displaynameview settext:item.displaynameofitemowner];      [cell.timeagoview settext:item.timeago];    [cell.imageview setimage:[uiimage imagenamed:@"sis_profile_placeholder"]];       cell.bounds = cgrectmake(0.0f, 0.0f, cgrectgetwidth(tableview.bounds), cgrectgetheight(_prototypecell.bounds));      [cell setneedslayout];     [cell layoutifneeded];       cgfloat height = [cell.contentview systemlayoutsizefittingsize:uilayoutfittingcompressedsize].height;     return height+1; } 

and height got [cell.contentview systemlayoutsizefittingsize:uilayoutfittingcompressedsize] alway "nil" " when tried debug ,i found subviews of customcell "nil" cell not "nil". might because customcell of mine made nib , when [[customcell alloc] init] cell not created.

but did tried change method cell = [_tableview dequeuereusablecellwithidentifier:@"customcell"];

the result still same. every subview nil . make height return 0 , make tableview display incorrectly. there way solve ?

i tried make these upon autolayout .actually, in previous version ,that didn't use autolayout , calculate cell height manually .it did work perfectly. anyway, want tried autolayout.

please .thanks in advance

here solution alloc new cell nsarray *toplevelobjects = [[nsbundle mainbundle] loadnibnamed:@"customcell" owner:self options:nil]; // grab pointer first object (presumably custom cell, that's xib should contain).

        cell = [toplevelobjects objectatindex:0];    -(cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath    *)indexpath  {  mydataitem *item= [[data items] objectatindex:[indexpath row]];      customcell *cell = [self.offscreencells objectforkey:@"customcell"]; if (!cell) {          nsarray *toplevelobjects = [[nsbundle mainbundle] loadnibnamed:@"customcell" owner:self options:nil];  // grab pointer first object (presumably custom cell, that's xib should contain).          cell = [toplevelobjects objectatindex:0];      [self.offscreencells setobject:cell forkey:@"customcell"];   }      [cell.commentview settext:item.comment];  [cell.displaynameview settext:item.displaynameofitemowner];  [cell.timeagoview settext:item.timeago];   [cell.imageview setimage:[uiimage imagenamed:@"image"]];   cell.bounds = cgrectmake(0.0f, 0.0f, cgrectgetwidth(tableview.bounds), cgrectgetheight(_prototypecell.bounds));  [cell setneedslayout]; [cell layoutifneeded];   cgfloat height = [cell.contentview systemlayoutsizefittingsize:uilayoutfittingcompressedsize].height; return height+1; } 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -