ios - Getting height of UITableViewCell class without subclassing -
i'm trying calculate height of uitableviewcell without doing whole dance boundingrectwithsize.
here's approach:
+ (cgfloat)heightforitem:(id<ddinfoitem>)item { if (!prototypecell) prototypecell = [[nsbundle mainbundle] loadnibnamed:nsstringfromclass([self class]) owner:nil options:nil][0]; [prototypecell configureforitem:item]; [prototypecell layoutifneeded]; cgsize size = [prototypecell.contentview systemlayoutsizefittingsize:uilayoutfittingcompressedsize]; return size.height+1; }
unfortunately, line
cgsize size = [prototypecell.contentview systemlayoutsizefittingsize:uilayoutfittingcompressedsize];
is returning nil... suspect because haven't set own constraints since not subclass of uitableviewcell. can confirm? there simple way of asking cell resize in situation?
thanks!
update
i still getting 0 height thought i've subclassed , added constraints in ib.
here's constraints on contentview in debugger:
<nslayoutconstraint:0x170091030 h:|-(nsspace(20))-[uilabel:0x12766b610] (names: '|':uitableviewcellcontentview:0x178361380 )>, <nslayoutconstraint:0x170094370 v:|-(nsspace(20))-[uilabel:0x12766b610] (names: '|':uitableviewcellcontentview:0x178361380 )>, <nslayoutconstraint:0x1700992d0 h:[uilabel:0x12766b610]-(nsspace(20))-| (names: '|':uitableviewcellcontentview:0x178361380 )>, <nslayoutconstraint:0x170099500 v:[uilabel:0x12766b610]-(nsspace(8))-[uilabel:0x127559c20]>, <nslayoutconstraint:0x170099000 h:[uilabel:0x127559c20]-(nsspace(20))-| (names: '|':uitableviewcellcontentview:0x178361380 )>, <nslayoutconstraint:0x17009c430 h:|-(nsspace(20))-[uilabel:0x127559c20] (names: '|':uitableviewcellcontentview:0x178361380 )>
note have replaced prototype cell's initwithstyle:identifier: nib loading method.
also, when log size of labels, indeed appear correctly resizing. result of calling systemlayoutsizefittingsize: still giving me 0 height :/
you're asking height in process. height 0 because @ point height has not been determined yet.
Comments
Post a Comment